In my program, the image can be converted to symmetric flip. However, if you think about it carefully, you will find that it is useless. But let's talk about the implementation principle.
Previously, image processing is often based on processing the values in each pixel of an image. Therefore, this principle applies to the image flip effect.
For example, if you want to flip the image between the left and right,
/// <Summary>
/// Flip the image
/// </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>
/// <Returns> flipped image </returns>
Public Bitmap RevPic (Bitmap mybm, int width, int height)
{
Bitmap bm = new Bitmap (width, height); // Initialize an image object after record processing
Int x, y, z; // x, y is the number of cycles, and z is used to record the x coordinate changes of the pixel.
Color pixel;
For (y = height-1; y> = 0; y --)
{
For (x = width-1, z = 0; x> = 0; x --)
{
Pixel = mybm. GetPixel (x, y); // obtain the value of the current pixel.
Bm. SetPixel (z ++, y, Color. FromArgb (pixel. R, pixel. G, pixel. B); // plot
}
}
Return bm; // return the flipped image.
}
The specific understanding may need to be illustrated, so I have not done this step here, but it should be okay to understand it on the draft paper.
The picture is flipped between the left and right sides, and of course there will be flip up and down. In fact, the principle is similar. The implementation code is as follows,
Public Bitmap RevPic (Bitmap mybm, int width, int height)
{
Bitmap bm = new Bitmap (width, height );
Int x, y, z;
Color pixel;
For (x = 0; x <width; x ++)
{
For (y = height-1, z = 0; y> = 0; y --)
{
Pixel = mybm. GetPixel (x, y); // obtain the value of the current pixel.
Bm. SetPixel (x, z ++, Color. FromArgb (pixel. R, pixel. G, pixel. B); // plot
}
}
Return bm; // return the flipped Image
}
As for the above section of code that implements "flip up and down", I will not write any comments. I am a lazy person. If I don't understand it, I can read the comments from "flip up and down, in fact, they are similar.
Finally, we need to use pictureBox to display the processed image!