Jump to content

is there any way to create a new layer using a plugin


Go to solution Solved by otuncelli,

Recommended Posts

20 minutes ago, WallyTheSapien said:

I couldn't find out whether your able to create a new layer via a plugin and I would like to know how to if it is able to be done

 

Not possible, see https://forums.getpaint.net/topic/14566-what-is-and-isnt-possible-when-writing-plugins/.

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Link to comment
Share on other sites

  • Solution

Sure.

 

using PaintDotNet;
...
...

// surface contains the pixel data
Surface surface = new Surface(width, height, SurfaceCreationFlags.DoNotZeroFillHint);

// add your surface to a layer
BitmapLayer layer = new BitmapLayer(surface, takeOwnership: true)
{
  Name = "Layer Name",
  Visible = true,
  BlendMode = LayerBlendMode.Normal, 
  Opacity = 255
};

// then add the layer to a document
Document document = new Document(width, height);
document.Layers.Add(layer);

 

  • You're a Smart Cookie! 1
Link to comment
Share on other sites

3 hours ago, WallyTheSapien said:

I couldn't find out whether your able to create a new layer via a plugin and I would like to know how to if it is able to be done


What are you actually trying to achieve with your plugin that would require the creation of a new layer? If you explain the context, then people may be able offer you a solution in a different way.

Link to comment
Share on other sites

14 hours ago, Tactilis said:


What are you actually trying to achieve with your plugin that would require the creation of a new layer? If you explain the context, then people may be able offer you a solution in a different way.

so I'm trying to make a plugin that splits an height map into deferent layers depending on the height

Link to comment
Share on other sites

17 hours ago, otuncelli said:

Sure.

 

using PaintDotNet;
...
...

// surface contains the pixel data
Surface surface = new Surface(width, height, SurfaceCreationFlags.DoNotZeroFillHint);

// add your surface to a layer
BitmapLayer layer = new BitmapLayer(surface, takeOwnership: true)
{
  Name = "Layer Name",
  Visible = true,
  BlendMode = LayerBlendMode.Normal, 
  Opacity = 255
};

// then add the layer to a document
Document document = new Document(width, height);
document.Layers.Add(layer);

 

I'm trying to add this to my file type plugin but I can't figure out how to add it too it correctly

 

Link to comment
Share on other sites

32 minutes ago, WallyTheSapien said:

I would also want to know how to export the layers as separate files in like a zip file

 

This already exists:

 

https://forums.getpaint.net/topic/31996-zip-archive-filetype-plugin-zip-latest-v14-2021-11-04/

 

Link to comment
Share on other sites

You need to derive your plugin class from FileType or PropertyBasedFileType or FileType<TToken, TTWidget> and implement IFileTypeFactory or IFileTypeFactory2 (newer, recommended) interfaces.

 

Derive from FileType if you don't need to show any settings on Save dialog, 

Derive from PropertyBasedFileType if you need to show settings on Save dialog using paint.net's internal controls, aka "IndirectUI", 

Derive from FileType<TToken, TTWidget> if you need to show settings on Save dialog using your own controls

 

You need to implement your own dialog and controls if you need to show settings when opening a file (in OnLoad method). This isn't something supported officially but possible.

 

A very simple implementation that derives from FileType:

https://github.com/PsdPlugin/PsdPlugin/blob/master/PhotoShopFileType/PhotoshopFileType.cs

 

The code I've posted should go into the Document OnLoad(System.IO.Stream input) method. You create the document using the input stream, return it and then paint.net opens it. 

 

Also @null54 has lots of open source file type plugins. They helped me a lot when learning stuff.

https://github.com/0xC0000054?tab=repositories&q=paint.net+filetype

Edited by otuncelli
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...