Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 绘制.net文件类型插件_C#_Paint.net - Fatal编程技术网

C# 绘制.net文件类型插件

C# 绘制.net文件类型插件,c#,paint.net,C#,Paint.net,找不到有关如何为Paint.net编写文件类型插件的任何信息。我在中仅找到visual studio模板 codeproject的小说明,但我不了解OnSave事件处理程序的所有参数,什么是PaintDotNet.Surface,以及如何处理存储在那里的数据。我曾经编写过这样的插件。 先别管模板了,你可以从头开始 首先添加对PaintDotnet.Base、PaintDotnet.Core和PaintDotnet.Data的引用 接下来,您需要一个从FileType类继承的类: 例如: publ

找不到有关如何为Paint.net编写文件类型插件的任何信息。我在中仅找到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您要加载哪些文件类型类,在本例中是一个实例,但在单个库中可以有多个实例

public class SampleFileTypeFactory : IFileTypeFactory
{
    public FileType[] GetFileTypeInstances()
    {
        return new FileType[] { new SampleFileType() };
    }
我希望这有帮助,如果你有问题,请告诉我。
}

非常感谢您的帮助,我还有一些问题。令牌、scratchSurface和回调需要什么?