aewarnick Posted August 15, 2003 Posted August 15, 2003 (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 August 15, 2003 by aewarnick Quote C#
OnErr0r Posted August 20, 2003 Posted August 20, 2003 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. Quote
aewarnick Posted August 20, 2003 Author Posted August 20, 2003 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? Quote C#
OnErr0r Posted August 20, 2003 Posted August 20, 2003 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. Quote
aewarnick Posted August 20, 2003 Author Posted August 20, 2003 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? Quote C#
*Experts* Nerseus Posted August 20, 2003 *Experts* Posted August 20, 2003 Are you asking how to "undo" the MakeTransparent call? -Nerseus Quote "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
aewarnick Posted August 20, 2003 Author Posted August 20, 2003 Yes and no. Yes I am but not in my previous post. They are both questions I really would like answers to. Quote C#
*Experts* Volte Posted August 20, 2003 *Experts* Posted August 20, 2003 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. Quote
aewarnick Posted August 20, 2003 Author Posted August 20, 2003 Slow huh? That's too bad. Thanks everyone for your help. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.