如果检测PNG图像文件是一个透明的形象? [英] Detecting if a PNG image file is a Transparent image?

查看:239
本文介绍了如果检测PNG图像文件是一个透明的形象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来快速确定一个PNG图像具有透明的特点。即,图像的任何部分是半透明的或显示以任何方式的背景。有谁人知道一个简单的方法来检测呢?

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?

更新:好吧,有没有那么一个不太复杂的方式拉出PNG规范和黑客code?

UPDATE: OK, is there a less complicated way then to pull out the PNG specification and hacking code?

推荐答案

为什么要通过所有的图像,并检查他们的Alpha值?像素的不只是环

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

这篇关于如果检测PNG图像文件是一个透明的形象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆