我目前正在使用一个检查图像是否为特定大小的函数,如果是,我将其转换为jpeg(例如:如果它是一个大png,则转换为jpeg)。
我想知道是否有一个允许你检查透明度的C#函数。如果图像是透明的,则保持透明并且不进行转换。
任何正确方向的帮助都会很棒。谢谢!
答案 0 :(得分:1)
我还没有测试过,但也许这个代码段可以正常运行:
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
}
}
}