首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Paint.net文件类型插件

Paint.net文件类型插件
EN

Stack Overflow用户
提问于 2010-06-28 22:21:14
回答 1查看 2.3K关注 0票数 4

找不到任何有关如何为Paint.net编写文件类型插件的信息。我在http://forums.getpaint.net/index.php?/topic/7984-filetype-plugin-template-v20/page__p__121651&#entry121651上只找到了visual studio模板

我并不了解OnSave事件处理程序的所有参数,什么是PaintDotNet.Surface,以及如何处理存储在那里的数据。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-29 21:41:55

我曾经写过一次这样的插件。暂时忘掉模板,你可以从头开始做。

首先添加对PaintDotnet.Base、PaintDotNet.Core和PaintDotNet.Data的引用。

接下来,您将需要一个继承自FileType类的类:

例如:

代码语言:javascript
复制
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。在构造函数中,您可以指定支持哪些操作(加载/保存)以及应该注册哪些文件扩展名。然后为Save和Load操作提供逻辑。

基本上,这就是您所需要的。

最后,您必须告诉Pain.Net您想要加载哪些FileType类,在本例中是一个实例,但是您可以在一个库中有多个实例。

代码语言:javascript
复制
public class SampleFileTypeFactory : IFileTypeFactory
{
    public FileType[] GetFileTypeInstances()
    {
        return new FileType[] { new SampleFileType() };
    }

我希望这对你有所帮助,如果你有什么问题,请告诉我。}

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3133165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档