Gettingwhich colors are transparent in a Bitmap

aewarnick

Well-known member
Joined
Jan 29, 2003
Messages
1,031
Getting which colors are transparent in a Bitmap

I would like a way to know which colors are transparent on my image when I use b.MakeTransparent(color); Is there a .net way to do that or do I have to keep track manually?

Also, how would I remove the transparency?
 
Last edited by a moderator:
If youre talking about a paletted image 2-256 colors then you can look at the palette fairly quickly using b.Palette.Entries(index).A(). I think the .net implmentation gets a little confused with 8 bit (and less) images as b.Palette.Flags() is not equal to HasAlpha as expected (System.Drawing.Imaging.PaletteFlags HasAlpha), most likely because its in 32 bit mode (or thinks it is)

If the image is not paletted then youre stuck looking through the image for alpha. Here is an example searching an image using unsafe:
http://www.fawcette.com/vsm/2003_06/magazine/columns/desktopdeveloper/

Removing transparency is just a matter of setting the alpha component of a color to 255.
 
A is for the whole image. What I meant was just one color in the image that is set as transparent. Will your solution get which color that is?
 
If the image has a palette, then you can get the alpha setting of a particular color using b.Palette.Entries(index).A(). If A() is < 255 then there is some alpha transparency set for the color at index. Youd check each color in a loop. Or, if the image has no palette, then use the code in the url provided.
 
Well then that brings me to another question then. Can I draw my whole image to the screen pixel by pixel instead of using DrawImage that way?

If so, will it be the same speed or faster?
 
Yes and no. Yes I am but not in my previous post. They are both questions I really would like answers to.
 
aewarnick: That will most likely be unreasonably slow, since there is (oddly) no function to draw a point in GDI+, so youd need to draw many 1x1 rectangles.
 
Back
Top