Plugin.cs (for PS)

来源:互联网 发布:娇韵诗淘宝旗舰店真假 编辑:程序博客网 时间:2024/05/17 21:41

/**
 * FluffyApp Photoshop plugin
 * Copyright (c) 2011-2012 Richard Z.H. Wang
 * Licensed under New BSD
 */

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;

/*
namespace Uploadinator.TriggerPlugins.Photoshop
{
    [Plugin("Photoshop",
        Version = "0.1.1",
        Description = "Uploads an image of the currently active tab's state.",
        Author = "Richard Z.H. Wang",
        Supports = "1.1.0",
        TriggeredBy = "Photoshop.exe")]
    public class Plugin : IPlugin
    {
        public PluginResult OnTriggered(PluginTriggerEventArgs e)
        {
            string dir = Path.Combine(Path.GetTempPath(), "FluffyApp");
            Directory.CreateDirectory(dir);

            Type photoshopType = Type.GetTypeFromProgID("Photoshop.Application");
            if (photoshopType != null)
            {
                object photoshop = Activator.CreateInstance(photoshopType);

                object activeDocument = photoshopType.InvokeMember("ActiveDocument", BindingFlags.GetProperty, null, photoshop, null);
                string activeFilename = (string)activeDocument.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, activeDocument, null);

                string savePath = Path.Combine(dir, Path.GetFileNameWithoutExtension(activeFilename) + ".png");

                Type saveOptionsType = Type.GetTypeFromProgID("Photoshop.PNGSaveOptions");
                object saveOptions = Activator.CreateInstance(saveOptionsType);

                activeDocument.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, activeDocument, new object[]
                {
                    savePath,
                    saveOptions,
                    true,
                    2 // lowercase
                });

                return PluginResult.FromPath(savePath);
            }

            return null;
        }
    }
}
*/

原创粉丝点击