Detecting if a PNG image file is a Transparent image?

后端 未结 3 1743
闹比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:35

    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.

提交回复
热议问题