Ii. Color Removal
This function completes the grayscale processing of the image. Our basic idea is to take the average value of the three color components of each pixel point. However, due to the sensitivity of human eyes, the effect of completely average value acquisition is not good. Program In, I took three parameters with the best results:. 299,. 587,. 114. However, it should be noted that in GDI +, the image storage format is BGR rather than RGB, that is, the order is blue, green, and red. Therefore, you must set the values of red, green, blue, and other variables in the for loop. If the function is successfully executed, true is returned. 1 Public Static Bool Gray (Bitmap B)
2 {
3 Bitmapdata bmdata = B. lockbits ( New Rectangle ( 0 , 0 , B. Width, B. Height ),
4 Imagelockmode. readwrite, pixelformat. format24bpprgb );
5 Int Stride = Bmdata. stride;
6 System. intptr scan0 = Bmdata. scan0;
7 Unsafe
8 {
9 Byte * P = ( Byte * )( Void * ) Scan0;
10 Int Noffset = Stride - B. Width * 3 ;
11 Byte Red, green, blue;
12 For ( Int Y = 0 ; Y < B. height; ++ Y)
13 {
14 For ( Int X = 0 ; X < B. width; ++ X)
15 {
16 Blue = P [ 0 ];
17 Green = P [ 1 ];
18 Red = P [ 2 ];
19 P [ 0 ] = P [ 1 ] = P [ 2 ] = ( Byte )(. 299 * Red + . 587 * Green + . 114 * Blue );
20 P + = 3 ;
21 }
22 P + = Noffset;
23 }
24 }
25 B. unlockbits (bmdata );
26 Return True ;
27 }
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