Jump to content

Importing layers with retained transparency


sjd
 Share

Recommended Posts

I've implemented code (in v2.1 base) to export a layer into a single RGB32 BMP. On import to layer, I can set the BitmapLayer Opacity to whatever I need. If the original saved layer had regions removed (set fully transparent ?) so the background is visible, these transparent regions are not reloaded (in Surface CopyFromBitmap).

Is this a deficiency in .NET's Bitmap.Save methods or have I missed something the Surface class and how the GDI+ aliased bitmap is produced.

Does deleting a region in a layer set that region Aplha values to 0, or is there a Transparency colour I've not yet spotted?

regards SJD

Link to comment
Share on other sites

From what I've seen, Bitmap.Save does not save a bitmap's alpha channel. The BMP file format apprently doesn't really support it -- or, to be more exact, apparently none of the codecs that come with the system do. (yes, I agree it's odd)

If you want to keep the transparency, I'd recommend saving with PNG or TGA. It's quite simple to do this in Paint.NET because we already have simple codecs in place for doing this.

Some pseudo code ...

Document just1layer = new Document(width, height);
just1Layer.Layers.Add(theLayerYouWant);
TgaFileType tft = new TgaFileType();
tft.Save(document, filename);

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Thanks Rick,

I've also noticed other problems with BMP codecs. I currently use 16 bit BMPs to save 12bpp mono industrial camera dark current images. Because Format16bppGrayscale does not get saved/restored correctly (grrrr!), I use Format16bppRgb565. Details in the header cause Explorer to think its a 32 bit file, even though the BitmapData format is reported as 16 bit. If I create Format16bppRgb565 using C++ and create the headers Explorer is happy. I have not figured out a way to access the header (BITMAPINFOHEADER) in C# as yet.

I was considering writing my own BMP Load and Save overrides derived from the Image class, as the Bitmap class is sealed. I'll look into using PNG instead.

regards,

SJD

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.

 Share

×
×
  • Create New...