Paint.net File Plugins

There is no way to find information on how to write a filetype plugin for Paint.net. I found only a visual studio template in http://forums.getpaint.net/index.php?/topic/7984-filetype-plugin-template-v20/page__p__121651&#entry121651

and a short description in codeproject, but I don’t understand all the parameters of the OnSave event handler, what PaintDotNet.Surface is and how to work with the data stored there.

+3
source share
1 answer

I wrote such a plugin once. Forget about the template in a minute, you can do it from scratch.

Start by adding links to PaintDotnet.Base, PaintDotNet.Core, and 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() };
    }

, , , .   }

+8

Source: https://habr.com/ru/post/1752093/


All Articles