Detecting if a PNG image file is a Transparent image?

后端 未结 3 1742
闹比i
闹比i 2020-12-06 05:10

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 a

3条回答
  •  长情又很酷
    2020-12-06 05:18

    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;
        }
    

提交回复
热议问题