Today, let's talk about how to make a picture black and white, that is, to make the image black and white. The method for opening the image has been published. The specific address is:
C # Image Processing (I)
In the face of another image that needs to be processed as a black/white image, I wrote the following function for it,
/// <Summary>
/// Convert the image to a black or white image
/// </Summary>
/// <Param name = "mybt"> image to be processed </param>
/// <Param name = "width"> image length </param>
/// <Param name = "height"> image height </param>
/// <Returns> processed black and white images </returns>
Public Bitmap BWPic (Bitmap mybm, int width, int height)
{
Bitmap bm = new Bitmap (width, height); // initialize a Bitmap object to record the processed image
Int x, y, result; // x, y indicates the number of cycles, and result indicates the processed pixel value.
Color pixel;
For (x = 0; x <width; x ++)
{
For (y = 0; y {
Pixel = mybm. GetPixel (x, y); // obtain the pixel value of the current coordinate.
Result = (pixel. R + pixel. G + pixel. B)/3; // average value of three colors: Red, green, and blue
// Plot and assign the processed value to the defined bm object
Bm. SetPixel (x, y, Color. FromArgb (result, result, result ));
}
}
Return bm; // return the black-and-white image
}
Finally, a pictureBox control is used to present the processed image. The following statement is used,
Int width = this. pictureBox. Width; // The length of the image container.
Int height = this. pictureBox. Height; // The width of the image container.
This. pictureBox. Image = pix. BWPic (Bitmap) this. pictureBox. Image, width, height); // process the Image