[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

System.Drawing.Bitmap alpha

instruo

1/22/2005 1:59:00 AM

I'm using the System.Drawing.Bitmap class for loading a 32-bit bmp file which
includes an alpha channel.

The problem is, when it gets loaded (just using the Bitmap(string filename)
constructor), it doesn't bother bringing the alpha along with it. All of the
pixels just show "255" as their alpha value and Bitmap.IsAlphaPixelFormat()
returns false.

I know that the alpha does exist physically and has worked with this exact
image in other contexts. So, does anyone know how I can make Bitmap behave
and actually give me my alpha channel in the file? Thanks much.

P.S. Don't mean to double post, but I was told in another forum that I
should post here because an individual named Bob Powell might be able to help
me out (not that I would appreciate help from anyone : ) Thanks!

2 Answers

Bob Powell

1/22/2005 11:54:00 AM

0

As far as I know, and this is buried in the unmanaged portion of GDI+ so I
can't disassemble it, the Bitmap image decoders always assume 24 bits per
pixel and lose the alpha channel. The PNG encoder / decoder is the only one
that accurately reads and writes the alpha channel.

I think that the only solution is to read the bitmap manually and decode the
pixel values from the raw byte stream.

My email address is obfuscated. Please remove the _spamkiller_ and send me
the image in question. I'll do some experiments.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"instruo" <instruo@discussions.microsoft.com> wrote in message
news:5F43E71F-4E9C-4B4B-92A2-56D0760017B0@microsoft.com...
> I'm using the System.Drawing.Bitmap class for loading a 32-bit bmp file
> which
> includes an alpha channel.
>
> The problem is, when it gets loaded (just using the Bitmap(string
> filename)
> constructor), it doesn't bother bringing the alpha along with it. All of
> the
> pixels just show "255" as their alpha value and
> Bitmap.IsAlphaPixelFormat()
> returns false.
>
> I know that the alpha does exist physically and has worked with this exact
> image in other contexts. So, does anyone know how I can make Bitmap behave
> and actually give me my alpha channel in the file? Thanks much.
>
> P.S. Don't mean to double post, but I was told in another forum that I
> should post here because an individual named Bob Powell might be able to
> help
> me out (not that I would appreciate help from anyone : ) Thanks!
>


Mick Doherty

1/22/2005 5:30:00 PM

0

I did give a response in the csharp forum where you originally posted.
Was the solution I offered not acceptable?

--
Mick Doherty
http://dotnetrix.co.uk/no...


"instruo" <instruo@discussions.microsoft.com> wrote in message
news:5F43E71F-4E9C-4B4B-92A2-56D0760017B0@microsoft.com...
> I'm using the System.Drawing.Bitmap class for loading a 32-bit bmp file
> which
> includes an alpha channel.
>
> The problem is, when it gets loaded (just using the Bitmap(string
> filename)
> constructor), it doesn't bother bringing the alpha along with it. All of
> the
> pixels just show "255" as their alpha value and
> Bitmap.IsAlphaPixelFormat()
> returns false.
>
> I know that the alpha does exist physically and has worked with this exact
> image in other contexts. So, does anyone know how I can make Bitmap behave
> and actually give me my alpha channel in the file? Thanks much.
>
> P.S. Don't mean to double post, but I was told in another forum that I
> should post here because an individual named Bob Powell might be able to
> help
> me out (not that I would appreciate help from anyone : ) Thanks!
>