Check if a Bitmap has tranparency
-
Hi all, So I have a Bitmap field, now I want to save it to disk, BUT if it has some transparent pixels, I want to save it as a gif, else save as jpg. Sounds reasonable? How can I do that? Thanks in advance, Danny
-
Hi all, So I have a Bitmap field, now I want to save it to disk, BUT if it has some transparent pixels, I want to save it as a gif, else save as jpg. Sounds reasonable? How can I do that? Thanks in advance, Danny
There is no such thing a transparent pixels in a bitmap. There's only transparency support in file formats, and in code that sets bitmasks. The png file format has transparency built in, but when you load a bitmap object it doesn't have support for transparency, it's just not part of the format.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
There is no such thing a transparent pixels in a bitmap. There's only transparency support in file formats, and in code that sets bitmasks. The png file format has transparency built in, but when you load a bitmap object it doesn't have support for transparency, it's just not part of the format.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Okay, so maybe my approach is wrong.. Situation: The user opened an image file, and I load it to a Bitmap, but I don't know if the image has some transparent regions. Now, regardless to the original user's image file's format, I want to save the image to disk, Image.Save (String, ImageFormat). So if the original image had some transparent regions, I would want to use an ImageFormat that has support for transparency (png/gif), and if there were no transparent regions, I would use Jpeg. Questions: Does this requirement make sense? How can I handle this kind of situation? Thanks, Danny