C # Image Processing (iv) -- color filter effect

Source: Internet
Author: User

In fact, if you have read the previous articles about black and white images and reversed images, you can easily process some simple images, because those only obtain the pixel values of the coordinates first, and then process these values. However, the filter effect is similar. The function to implement the filter effect is as follows,

/// <Summary>
/// Filter 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> filtered images </returns>
Public Bitmap FilPic (Bitmap mybm, int width, int height)
{
Bitmap bm = new Bitmap (width, height); // Initialize an image object that records the color filter effect.
Int x, y; // number of cycles
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.
Bm. SetPixel (x, y, Color. FromArgb (0, pixel. G, pixel. B); // plot
}

}

Return bm; // return the filtered image.

}

Here, we only implement the filtering effect of the red color. I don't know if you have noticed it. In fact, we only changed the value of a parameter in the plotting process. SetPixel (x, y, Color. fromArgb (pixel. r, pixel. g, pixel. b. fromArgb (pixel. r, pixel. g, pixel. b) the three parameters are actually red values, green values, and Blue values. The filter principle is to assign a value of 0 to the color to be filtered, in the above example, the red value of the image is filtered out, because I set the Color. fromArgb (pixel. r, pixel. g, pixel. b) pixel. the value of R is directly assigned to 0, and the other two values remain unchanged, then the filter effect can be achieved. Of course, it can also be used to filter the green, blue, red, and green colors, or even filter all colors, but filter all the colors to make the entire picture black, what is the use of this effect?

In my program, the effect I made is to filter the color according to the user's requirements, so the above function is not the source code in my program, it is missing an int variable. The last step is 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.