Converting RGB images to grayscale

孤者浪人 提交于 2019-12-10 12:26:56

问题


I'm new on programming. I'm a student in a univesity. Is it possible to use visual studio for converting RGB images to grayscale with C#?

There is a specific folder that includes RGB jpeg images and every day it has new jpg files too. I need to make an exe file for converting them to grayscale.

Do I have to install new libraries for this work or are standard libraries of VS2013 enough for this?


回答1:


The standard libraries are enough.

I once used this code:

public static Bitmap GrauwertBild(Bitmap input) 
{
  Bitmap greyscale = new Bitmap(input.Width, input.Height);
  for (int x = 0; x < input.Width; x++)
  {
    for (int y = 0; y < input.Height; y++)
    {
     Color pixelColor = input.GetPixel(x, y);
     //  0.3 · r + 0.59 · g + 0.11 · b
     int grey = (int)(pixelColor.R * 0.3 + pixelColor.G * 0.59 + pixelColor.B * 0.11);
     greyscale.SetPixel(x, y, Color.FromArgb(pixelColor.A, grey , grey , grey ));
    }
  }
  return greyscale;
}


来源:https://stackoverflow.com/questions/21527518/converting-rgb-images-to-grayscale

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!