I am looking for a way to quickly determine if a PNG image has transparent features. Does anyone one know a simple way to detect this?
UPDATE: OK, is there a less complicated way then to pull out the PNG specification and hacking code?
I am looking for a way to quickly determine if a PNG image has transparent features. Does anyone one know a simple way to detect this?
UPDATE: OK, is there a less complicated way then to pull out the PNG specification and hacking code?
Why not just loop through all of the pixels in the image and check their alpha values?
bool ContainsTransparent(Bitmap image)
{
for (int y = 0; y < image.Height; ++y)
{
for (int x = 0; x < image.Width; ++x)
{
if (image.GetPixel(x, y).A != 255)
{
return true;
}
}
}
return false;
}
Well, i still don't understand the question completely, but if you just want to check, whether a given image may use transparency features, you can use this code:
Image img = Image.FromFile ( "...", true );
if ( (img.Flags & 0x2) != 0)
{
}
Though it won't help you to determine whether a given png file actually uses transparent features, it will indicate, that it has color type 4 or 6 (both support transparency) according to png file specification.