private Image translate(Image image)
{
try
{
int Height = image.Height;
int Width = image.Width;
Bitmap newbitmap = new Bitmap(Width, Height); //用于存放新图像
Bitmap oldbitmap = (Bitmap)image; //用于存放旧图像
Color pixel;
for (int x = 1; x < Width; x++)
{
for (int y = 1; y < Height; y++)
{
int r, g, b, Grayscale;
pixel = oldbitmap.GetPixel(x, y);
r = pixel.R;
g = pixel.G;
b = pixel.B;
Grayscale = (r + g + b) / 3;
if (Grayscale > 100)
{
r = 255;
g = 255;
b = 255;
}
newbitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
}
}
image = newbitmap;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return image;
}