[英]How to identify the image is greyscale image or color image in c#
我要求在具有高度属性的文件夹中验证大量图像(jpg,tif,png)。 但验证规则对于彩色图像和灰度图像是不同的。
但我的问题是
如何识别图像是c#中的灰度图像还是彩色图像?
至少从哪里开始?
bool IsGreyScale(Bitmap YourCurrentBitmap)
{
Color c;
for(int i=0; i < YourCurrentBitmap.Width; i++)
for(int j=0; j < YourCurrentBitmap.Height; j++)
{
c = YourCurrentBitmap.GetPixel(i,j);
if(!(c.R == c.G == c.B)) return false;
}
return true;
}
但是这种方法相对较慢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.