C # Image Processing (iii) -- Reversed Color Processing

Source: Internet
Author: User

Next, let's talk about how to turn an image into a reversed color. In fact, each pixel has four values, which are alpha, red, green, and blue. They are the basic elements of the color, at least I think so. The value range of each element is [0,255], that is, between 0 and 255. So the function for implementing the reversed color effect is calculated as follows,

/// <Summary>
/// Reversed 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> reversed image </returns>
Public Bitmap RePic (Bitmap mybm, int width, int height)
{
Bitmap bm = new Bitmap (width, height); // initialize the object of the image after record processing
Int x, y, resultR, resultG, resultB;
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.
ResultR = 255-pixel. R; // anti-red
ResultG = 255-pixel. G; // reverse green
ResultB = 255-pixel. B; // anti-blue
Bm. SetPixel (x, y, Color. FromArgb (resultR, resultG, resultB); // plot
}
}

Return bm; // returns the reversed image.
}

 

The last step is to use pictureBox to display the image in the form.

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.