Click here to Skip to main content
14,774,208 members
Articles » Multimedia » General Graphics » General
Article
Posted 25 Feb 2008

Stats

33.7K views
8 bookmarked

Creating Paint.NET FileType Plugins

Rate me:
Please Sign up or sign in to vote.
2.67/5 (5 votes)
25 Feb 2008CPOL
An article on how to create plug-ins for Paint.NET to allow it to import a new type of file.

Introduction

Paint.NET is a free image manipulation program that allows you to write plug-ins for it to add extra effects and include support for more file types. In this article, I will show you how to create FileType plug-ins for Paint.NET.

Downloading the Template

Firstly, you need to download the Paint.NET FileType plug-in template from here. Then, install it in the usual way.

Setting the Plug-in Properties

Firstly, create a new project using the template you have just downloaded. Then, modify the class arguments:

public MyFileType()
            : base("Text Document",
                FileTypeFlags.SupportsLoading | FileTypeFlags.SupportsSaving,
                new String[] { ".txt" })

Change "Text Document" to whatever you want the file type to be listed as in the Save dialog box. Modify ".txt" to the file extension of the file type you are trying to add. I would expect to modify the save and load constants there as well, but for some reason, if you do, it conflicts with other FileType plug-ins - so leave it as it is whether your plug-in supports both or not.

Adding Load Support

If your plug-in only supports saving, you can ignore this step. Now we are ready to add support for loading files into Paint.NET. Here is the important part of the load method:

protected override Document OnLoad(Stream input)
{
    try
    {
        Bitmap b = new Bitmap(500, 500);

        return Document.FromImage(b);
    }

Add code to read from the stream called input and fill the b object with the data collected in Bitmap form.

Adding Save Support

If your plug-in only supports loading, you can ignore this step. Here is the save function:

protected override void OnSave(Document input, Stream output, SaveConfigToken token,
          Surface scratchSurface, ProgressEventHandler callback)
{
    RenderArgs ra = new RenderArgs(new Surface(input.Size));
    input.Render(ra);

    ra.Bitmap.Save(output, ImageFormat.Bmp);
}

Delete the bottom line of code inside that function and replace it with code to use the ra.Bitmap object to write the image data to the output stream in the format we are targeting.

Publishing Your Plugin

To publish your plug-in, first you need to become a member of the Paint.NET forum (here). Then, start a new thread in this section and attach your plug-in as a zip file.

Adding an Installer

A great way to make life easier for the people installing your plug-in is to create an installer for it. There is a ready-made one that you can just download and add your plug-in to and distribute to your users here. To use it, just unzip, open the plugins folder, delete the text file inside it, and put your plug-in in there instead. Then, you can zip the installer up and instruct your users to unzip it and run "install.exe". Note that you should also provide a copy of the plug-in files as detailed in the last step, as many users don't have permission to run programs.

History

None yet.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

sabrown100
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
QuestionTemplate Pin
WildN00b20-Sep-10 9:59
MemberWildN00b20-Sep-10 9:59 
AnswerRe: Template Pin
IAbstract16-May-18 6:24
MemberIAbstract16-May-18 6:24 
AnswerRe: Template Pin
IAbstract16-May-18 6:27
MemberIAbstract16-May-18 6:27 
GeneralGreat example, thank you! Pin
TimothyP4-Sep-09 9:17
MemberTimothyP4-Sep-09 9:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.