Change a color photo to a black or white image

Source: Internet
Author: User
When I was a child, some photos were black and white. Now they are all colored and colorful. Instead, I think black and white are more pleasing to the eye. The colors are from (R (red), g (green ), B (blue) is composed of a mixture of 0 to 25 5, respectively. (R + G + B)/3, the color is black and white.
Program Simple 1   /**/ ///   <Summary>
2 /// Turns a color image into a black-and-white image.
3 ///   </Summary>
4 ///   <Param name = "image"> Original Image </Param>
5 ///   <Returns> Returned black and white photos </Returns>
6 Public   Static Bitmap whiteandblack (system. Drawing. bitmap image)
7 {
8 // Original Image Length
9 Int Width = Image. width;
10 // Original Image Height
11 Int Height = Image. height;
12 // Change Pigment
13 // Abscissa
14 For ( Int X =   0 ; X < Width; x ++ )
15 {
16 // Ordinate
17 For ( Int Y =   0 ; Y < Height; y ++ )
18 {
19 // Obtain the coordinate (x, y) color.
20 Color color = Image. getpixel (x, y );
21 // Obtain the black and white color.
22 Int Value = (Color. r + Color. g + Color. B) /   3 ;
23 // Set color
24 Image. setpixel (X, Y, color. fromargb (value, value, value ));
25 }
26 }
27 Return Image;
28 }

Test results:
Source image:

Black and white:

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.