I. Reverse Phase
In this function, the bitmapdata type bmdata contains the internal information of the image file. The stride attribute of bmdata specifies the width of a line, and its scan0 attribute is a pointer to the internal information of the image. This function is used to flip the image color. The method is to subtract the value of each pixel point from the image by 255, and set the value to the value at the original pixel point, this operation is performed on each pixel point only after the entire image is processed. Unsafe in Function Code Block is the main part of the entire function. First we get the pointer to the internal data of the image, set the offset, and set nwidth to B. width * 3, because each pixel point contains three color components, each pixel point must be processed three times. Next, we use two nested for loops to process each pixel point. The core of the processing is P [0] = (byte) (255-p [0]). After the Unsafe code block, you can use B. unlockbits (bmdata) to release image resources. If the function is successfully executed, true is returned. 1 Public Static Bool Invert (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 Int Nwidth = B. Width * 3 ;
12 For ( Int Y = 0 ; Y < B. height; ++ Y)
13 {
14 For ( Int X = 0 ; X < Nwidth; ++ X)
15 {
16 P [ 0 ] = ( Byte )( 255 - P [ 0 ]);
17 ++ P;
18 }
19 P + = Noffset;
20 }
21 }
22 B. unlockbits (bmdata );
23 Return True ;
24 }
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