Question How to detect transparency index or flag for a GIF or PNG image?

JollyBootsOfDoom

New member
Joined
Sep 22, 2008
Messages
1
Programming Experience
10+
Okay I'm loading a GIF or PNG with

VB.NET:
Dim Img1 as Image = Image.FromFile(FileName$)

Then, according to msdn, I should be able to retrieve the transparency index by doing the following:
VB.NET:
TransparencyIndex = Img1.GetPropertyItem(&h5104).Value(0)

&h5104 corresponds to the property item for the image's transparency index.
Each property item has an array of values, in this case there is only one value in the array, which is the transparency index.

Now here's the problem. For every image I've tried, there is no property item w/ id &h5104. But some of the GIFs do have transparencies, and when I redraw the GIF, it looks ugly because it doesn't erase parts of the old image. I don't want to have to clear the Graphics each time I redraw, because that causes flicker and flashing, but in the case of GIFs with transparencies, I'll have to.

On another forum, I read that you can get the transparency flag in the first 13 bytes of the file, but I realized that is not the case after analyzing those bytes and reading the GIF file spec online (the transparency flag and index are in something called a Graphic Control Extension, which I guess can occur anywhere in the file... I'm not trying to write 100 lines of code just to figure out if there is a transparency flag or not).

Sorry to make this so long, just trying to be thorough :)

I've looked all over the internet and just can't find a simple way to detect transparencies. Does anyone know how to do this? Also, if you know of a way around this problem, like maybe how to always clear the old image without causing flicker, I'm open to that kind of solution as well.
 
Back
Top