I am looking for a way to quickly determine if a PNG image has transparent features. That is, whether any portion of the image is translucent or displays the background in any way. 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?
Images that have transparency often illustrate it by using a gray and white checkered pattern. The idea is that you can see which parts of the image will be transparent before you save it. The checkered pattern is the background.
Click the Lasso Tool on the Tools panel. Hold and drag your cursor around the object you want to remove from the background. Create a new layer by clicking the New Layer icon at the bottom of the Layers panel. Make sure that the new layer is transparent.
Type in your search term and run your search as normal. After you get your results, click on "Tools" in the top menu to see the advanced search options. In the "Color" drop down menu choose the option for "Transparent". The results you get now will be images that have a transparent portion.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With