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.