C # adjusts picture brightness

Source: Internet
Author: User

Yesterday to the customer to test, the need to start, so very simple, is to test if you can accept the video or pictures, and then save it, the site customers said brightness is not enough, and then learn a C # adjust the brightness of the picture, record

Learn the post in this: http://blog.csdn.net/kenkao/article/details/3148091

/// <summary>        ///Image Brightness Adjustment/// </summary>        /// <param name= "B" >Original Diagram</param>        /// <param name= "degree" >brightness [ -255, 255]</param>        /// <returns></returns>         Public StaticBitmap Kilighten (Bitmap B,intdegree) {            if(b = =NULL)            {                return NULL; }            if(Degree <-255) degree =-255; if(Degree >255) degree =255; Try            {                intwidth =B.width; intHeight =B.height; intPIX =0; BitmapData Data= B.lockbits (NewRectangle (0,0, width, height), imagelockmode.readwrite, Pixelformat.format24bpprgb); unsafe                {                    byte* p = (byte*) data.                    Scan0; intoffset = data. Stride-width *3;  for(inty =0; Y < height; y++)                    {                         for(intx =0; x < width; X + +)                        {                            //handles the brightness of pixels at the specified position                             for(inti =0; I <3; i++) {pix= P[i] +degree; if(Degree <0) P[i] = (byte) Math.max (0, pix); if(Degree >0) P[i] = (byte) Math.min (255, pix); } //Ip + =3; } //xp + =offset; } //y} b.unlockbits (data); returnb; }            Catch            {                return NULL; }        } //End of Lighten
View Code

and then call

string @" C:\Users\wjr\Desktop\ for Business \1.png " ;             New Bitmap (@ "C:\Users\wjr\Desktop\ for Business \windowsformsapplication1\windowsformsapplication1\ windowsformsapplication1\bin\release\capture\20170417 025826019.png");              - );            A.save (Savepath);
Bitmap a = Kilighten (img, +);
I set here is 20, the range is -255~255, so 0 is the original picture brightness, I set the 20, so the picture brightness thought to show not obvious, I get a 100, look at the effect


C # adjusts picture brightness

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.