无法找到任何有关如何为Paint.net编写文件类型插件的信息。我发现只有在http://forums.getpaint.net/index.php?/topic/7984-filetype-plugin-template-v20/page__p__121651&#entry121651Paint.net文件类型插件
和codeproject的小描述,但我不明白OnSave事件处理程序的所有参数,什么是PaintDotNet.Surface和如何使用存储在那里的数据。
无法找到任何有关如何为Paint.net编写文件类型插件的信息。我发现只有在http://forums.getpaint.net/index.php?/topic/7984-filetype-plugin-template-v20/page__p__121651&#entry121651Paint.net文件类型插件
和codeproject的小描述,但我不明白OnSave事件处理程序的所有参数,什么是PaintDotNet.Surface和如何使用存储在那里的数据。
我写过这样一个插件一次。 暂时忘掉模板,你可以从头开始。
首先添加对PaintDotnet.Base,PaintDotNet.Core和PaintDotNet.Data的引用。
接下来,您将需要一个类从文件类型类继承:
例如:
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);
}
}
}
所以,你从文件类型继承。在构造函数中指定支持哪些操作(加载/保存)以及应注册哪些文件扩展名。然后,您为保存和加载操作提供逻辑。
基本上这就是你需要的一切。
最后,你将不得不告诉Pain.Net你想加载哪些FileType类,在这种情况下是单个实例,但是你可以在单个库中拥有多于一个的FileType类。
public class SampleFileTypeFactory : IFileTypeFactory
{
public FileType[] GetFileTypeInstances()
{
return new FileType[] { new SampleFileType() };
}
我希望这可以帮助,让我知道如果你有问题。 }
非常感谢您的帮助 我还有一些问题。什么是令牌,scratchSurface和回调需要? – kalan 2010-06-30 10:35:03