我可以帮助您进行翻译。以下是需要翻译的内容:
我已经编写了一些C#代码,将我的RGB图像转换为灰度图像,并且我想将灰度图像转换为只有两种颜色,黑色和白色。 你能帮忙吗?
代码:
Bitmap bmp = new Bitmap(file);
int width = bmp.Width;
int height = bmp.Height;
int[] arr = new int[225];
int i = 0;
Color p;
//Grayscale
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
p = bmp.GetPixel(x,y);
int a = p.A;
int r = p.R;
int g = p.G;
int b = p.B;
int avg = (r+g+b)/3;
bmp.SetPixel(x, y, Color.FromArgb(a, avg ,avg, avg));
}
}
pictureBox2.Image = bmp;