Back to the implementation of image-oriented pixel processing. Think about it. If I knew it, I would like to advance the "adjust the brightness of the image" part to Image Processing (6), because this part is similar to the principles of (2) to (5. But forget it. If you don't want to change it, write it down.
In my personal understanding, adjusting the brightness of an image is done by adding a constant to the red, green, and Blue values in each pixel. In fact, it is useless to describe more and paste the Code directly,
/// <Summary>
/// Adjust the image brightness
/// </Summary>
/// <Param name = "mybm"> original image </param>
/// <Param name = "width"> length of the original image </param>
/// <Param name = "height"> height of the original image </param>
/// <Param name = "val"> increase or decrease the light/dark value </param>
/// <Returns> the image after being dimmed </returns>
Public Bitmap LDPic (Bitmap mybm, int width, int height, int val)
{
Bitmap bm = new Bitmap (width, height); // Initialize an image object after record processing
Int x, y, resultR, resultG, and resultB; // x and y indicate the number of cycles, and the last three values indicate the values of red, green, and blue.
Color pixel;
For (x = 0; x <width; x ++)
{
For (y = 0; y {
Pixel = mybm. GetPixel (x, y); // obtain the value of the current pixel.
ResultR = helper. CheckRange (pixel. R + val); // check if the red value exceeds [0,255]
ResultG = helper. CheckRange (pixel. G + val); // check if the green value exceeds [0,255]
ResultB = helper. CheckRange (pixel. B + val); // check if the blue value exceeds [0,255]
Bm. SetPixel (x, y, Color. FromArgb (resultR, resultG, resultB); // plot
}
}
Return bm; // return the image after the light is dimmed.
}
The CheckRange function is used to check whether the modified red, green, and Blue values exceed the range [0,255]. As for this function, it is relatively simple, so I am sorry to post the code.
By the way, you can use the numericUpDown control to obtain the light and dark values, which is more convenient, because I did this, note that the numericUpDown value obtained through the numericUpDown control. value should be used to forcibly convert the int type, that is, (int) numericUpDown. value.
At last, you should use pictureBox to display the adjusted image.