• Advertisement
Sign in to follow this  

GDI Bitmap from .bmp file transparency lost

This topic is 2105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know most think bmp's dont support alpha but it does, I cant use png thats far too slow so I need a way of making a Bitmap object from a bmp with alpha in a byte[]/MemoryStream and I'm currently using this:
[color=black]var[/color] [color=yellow]gch[/color] = [color=#2b91af]GCHandle[/color].[color=yellow]Alloc[/color](>>>heres the bmp in a byte[]<<<, [color=#2b91af]GCHandleType[/color].[color=yellow]Pinned[/color]);
[color=black]var[/color] [color=yellow]bmp[/color] = [color=black]new[/color] [color=#2b91af]Bitmap[/color]([color=yellow]_res[/color].[color=yellow]Width[/color], [color=yellow]_res[/color].[color=yellow]Height[/color], 4 * [color=yellow]_res[/color].[color=yellow]Width[/color], [color=#2b91af]PixelFormat[/color].[color=yellow]Format32bppArgb[/color], ([color=#2b91af]IntPtr[/color])(([color=black]int[/color])([color=yellow]gch[/color].[color=yellow]AddrOfPinnedObject[/color]()) + 54));
[color=yellow]bmp[/color].[color=yellow]RotateFlip[/color]([color=#2b91af]RotateFlipType[/color].[color=yellow]RotateNoneFlipY[/color]);
[color=yellow]gch[/color].[color=yellow]Free[/color]();
the RotateFlip is required because the image comes out inverted but it sometimes throws an AccessViolationException which is an exception in unmanaged code that I cant catch but an InvalidOperationException is caught when I step it.

So is there an alternative or a simple fix for my existing code?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement