找不到有关如何为 Paint.net 编写文件类型插件的任何信息。我只在http://forums.getpaint.net/index.php?/topic/7984-filetype-plugin-template-v20/page__p__121651&#entry121651找到了 Visual Studio 模板
和 codeproject 的小描述,但我不了解 OnSave 事件处理程序的所有参数,什么是 PaintDotNet.Surface 以及如何处理存储在那里的数据。
找不到有关如何为 Paint.net 编写文件类型插件的任何信息。我只在http://forums.getpaint.net/index.php?/topic/7984-filetype-plugin-template-v20/page__p__121651&#entry121651找到了 Visual Studio 模板
和 codeproject 的小描述,但我不了解 OnSave 事件处理程序的所有参数,什么是 PaintDotNet.Surface 以及如何处理存储在那里的数据。
我曾经写过这样的插件。暂时忘记模板,您可以从头开始执行此操作。
首先添加对 PaintDotnet.Base、PaintDotNet.Core 和 PaintDotNet.Data 的引用。
接下来,您需要一个继承自 FileType 类的类:
例如:
public class SampleFileType : FileType
{
public SampleFileType() : base ("Sample file type", FileTypeFlags.SupportsSaving |
FileTypeFlags.SupportsLoading,
new string[] { ".sample" })
{
}
protected override void OnSave(Document input, System.IO.Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
{
//Here you get the image from Paint.NET and you'll have to convert it
//and write the resulting bytes to the output stream (this will save it to the specified file)
using (RenderArgs ra = new RenderArgs(new Surface(input.Size)))
{
//You must call this to prepare the bitmap
input.Render(ra);
//Now you can access the bitmap and perform some logic on it
//In this case I'm converting the bitmap to something else (byte[])
var sampleData = ConvertBitmapToSampleFormat(ra.Bitmap);
output.Write(sampleData, 0, sampleData.Length);
}
}
protected override Document OnLoad(System.IO.Stream input)
{
//Input is the binary data from the file
//What you need to do here is convert that date to a valid instance of System.Drawing.Bitmap
//In the end you need to return it by Document.FromImage(bitmap)
//The ConvertFromFileToBitmap, just like the ConvertBitmapSampleFormat,
//is simply a function which takes the binary data and converts it to a valid instance of System.Drawing.Bitmap
//You will have to define a function like this which does whatever you want to the data
using(var bitmap = ConvertFromFileToBitmap(input))
{
return Document.FromImage(bitmap);
}
}
}
因此,您从 FileType 继承。在构造函数中,您指定支持哪些操作(加载/保存)以及应注册哪些文件扩展名。然后为保存和加载操作提供逻辑。
基本上这就是你所需要的。
最后,您必须告诉 Pain.Net 您要加载哪些 FileType 类,在本例中为单个实例,但您可以在单个库中拥有多个。
public class SampleFileTypeFactory : IFileTypeFactory
{
public FileType[] GetFileTypeInstances()
{
return new FileType[] { new SampleFileType() };
}
我希望这会有所帮助,如果您有任何问题,请告诉我。}