Image processing algorithm (3)

Source: Internet
Author: User
Iii. brightness
This function is used to increase the brightness of the image. It has an addition parameter-nbrightness, Which is input by the user and ranges from-255 ~ 255. After obtaining the brightening parameter, the function's unsafe Code Processing the different color components of each pixel point one by one, that is, adding an brightening parameter to the original value to obtain the new value. At the same time, there is an operation in the code to prevent the score from crossing the border, because the RGB score range is 0 ~ 255. You need to reset the value once the value exceeds this range. After the function is successfully executed, true must be returned. 1 Public   Static   Bool Brightness (Bitmap B, Int Nbrightness)
2 {
3 If (Nbrightness <   - 255   | Nbrightness >   255 )
4 Return   False ;
5 Bitmapdata bmdata = B. lockbits ( New Rectangle ( 0 , 0 , B. Width,
6 B. Height), imagelockmode. readwrite,
7 Pixelformat. format24bpprgb );
8 Int Stride = Bmdata. stride;
9 System. intptr scan0 = Bmdata. scan0;
10 Int Nval =   0 ;
11 Unsafe
12 {
13 Byte   * P = ( Byte   * )( Void   * ) Scan0;
14 Int Noffset = Stride - B. Width * 3 ;
15 Int Nwidth = B. Width *   3 ;
16 For ( Int Y = 0 ; Y < B. height; ++ Y)
17 {
18 For ( Int X = 0 ; X < Nwidth; ++ X)
19 {
20 Nval = ( Int ) (P [ 0 ] + Nbrightness );
21 If (Nval <   0 ) Nval =   0 ;
22 If (Nval >   255 ) Nval =   255 ;
23 P [ 0 ] = ( Byte ) Nval;
24 ++ P;
25 }
26 P + = Noffset;
27 }
28 }
29 B. unlockbits (bmdata );
30 Return   True ;
31 }

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.