如何将位图图像转换为黑色和白色的C#?
问题描述:
可能重复:结果
的转换图像为黑白或棕褐在C#
我正在写一个C#应用程序,打开图像,点击一个按钮,显示它只有黑色和白色!
我肯定能找到很多在网络上的信息,但我的搜索没有给我很多的理解和有用的信息。
I'm writing a C# application, that opens an image, and clicking on a button, displays it in only black and white! I was sure to find a lot of information on the net, but my searches didn't give me a lot of understandable and useful information.
我有不知道如何着手。没有任何一个有什么建议吗?知道在网络上的教程?
I have no idea of how to proceed. Does any one have any advice ? Know a tutorial on the net?
答
有一次,我发现,转换位图以灰度功能
I once found a function that converts a bitmap to grayscale
public Bitmap GrayScale(Bitmap Bmp)
{
int rgb;
Color c;
for (int y = 0; y < Bmp.Height; y++)
for (int x = 0; x < Bmp.Width; x++)
{
c = Bmp.GetPixel(x, y);
rgb = (int)((c.R + c.G + c.B) / 3);
Bmp.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
}
return Bmp;
}
该函数接受位图作为参数,并且它在灰度返回位
The function accepts a bitmap as a parameter, and it returns the bitmap in grayscale.
我希望这有助于。