C # Image Processing (5) -- image flip

Source: Internet
Author: User
Tags image flip

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.