检查图像是否透明 [英] Check to see if image is transparent

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

问题描述

我目前正在使用一个功能,用于检查图像是否为特定大小,如果是,则将其转换为jpeg(例如:如果是大png,则转换为jpeg).

I currently am using a function that checks whether or not an image is a certain size and if so, I convert it to a jpeg (example: if it is a large png, convert to jpeg).

我想知道是否有一个C#函数可以让您检查透明度.如果图片是透明的,请保持透明,不要进行转换.

I was wondering if there was a C# function that allowed you to check for transparency. If the image is transparent, then keep it transparent and don't convert.

任何在正确方向上的帮助都将非常有用.谢谢!

Any help in the right direction would be great. Thanks!

推荐答案

我尚未测试过,但是也许该代码段可以使用:

I haven't tested, but maybe this snippet will work:

System.Drawing.Image myImage; //Set source from image here
System.Drawing.Bitmap myBitmap = new System.Drawing.Bitmap(myImage);

for (xPixel = 0; xPixel <= (myBitmap.Width - 1); xPixel++) {
    for (yPixel = 0; yPixel <= (myBitmap.Height - 1); yPixel++) {
        if (myBitmap.GetPixel(xPixel, yPixel) == Drawing.Color.Transparent) {
            // Image contains transparency
        }
    }
}

这篇关于检查图像是否透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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