Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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?

Edited by aewarnick
C#
Posted

If you're 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 it's in 32 bit mode (or thinks it is)

 

If the image is not paletted then you're 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.

Posted
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. You'd check each color in a loop. Or, if the image has no palette, then use the code in the url provided.
Posted

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?

C#
  • *Experts*
Posted

Are you asking how to "undo" the MakeTransparent call?

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted
aewarnick: That will most likely be unreasonably slow, since there is (oddly) no function to draw a point in GDI+, so you'd need to draw many 1x1 rectangles.

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...