【问题标题】:How to identify the image is greyscale image or color image in c#如何在c#中识别图像是灰度图像还是彩色图像
【发布时间】:2013-03-13 02:21:48
【问题描述】:

我需要验证具有高度属性的文件夹中的大量图像(jpg、tif、png)。但是彩色图像和灰度图像的验证规则不同。

但我的问题是

c#中如何识别图片是灰度图还是彩色图?

至少从哪里开始?

【问题讨论】:

  • 我相信 Image 或 Bitmap 类包含指定每像素位数的 ImageFormat 属性。不过,仅此还不够。您可能需要扫描每个像素并确保 r==g==b
  • 你能不能给我这么多的代码
  • 没有。网络上有大量示例展示了这一概念。

标签: c# image colors grayscale


【解决方案1】:
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;
}

但是这种方法比较慢。

【讨论】:

    猜你喜欢
    • 2012-01-09
    • 2014-07-18
    • 2019-03-04
    • 2021-10-06
    • 2015-11-20
    • 2021-12-13
    • 1970-01-01
    • 2010-12-19
    • 2014-07-02
    相关资源
    最近更新 更多