Private voidButton1_Click (Objectsender, EventArgs e) {Updatepicboxeventhandle Updatepicbox=NewUpdatepicboxeventhandle (setbrightness); Image img=pictureBox1.Image; for(intI =-255; I < the; i++{Updatepicbox.begininvoke (img). Clone () asBitmap, I,NewAsyncCallback (Updatepicboxcallback), updatepicbox); } } DelegateImage updatepicboxeventhandle (Image img,intcontrast); Public voidupdatepicboxcallback (IAsyncResult result) {if(result.) iscompleted) {Updatepicboxeventhandle Updatepicbox= result. AsyncState asUpdatepicboxeventhandle; using(Image img = updatepicbox.) EndInvoke (Result) asImage) { //img. Save (Guid.NewGuid (). ToString () + ". jpg");Picturebox2.image =NewBitmap (IMG); } } } /// <summary> ///Set Brightness/// </summary> /// <param name= "img" >Image</param> /// <param name= "Brightness" >-values from 255 to +255</param> /// <returns>Change of picture</returns> PublicImage setbrightness (Image img,intbrightness) { using(Bitmap tmp =(Bitmap) img) { if(Brightness <-255) Brightness =-255; if(Brightness >255) Brightness =255; Color C; //traversing image pixels for(inti =0; I < TMP. Width; i++) { for(intj =0; J < TMP. Height; J + +) {C= tmp. GetPixel (i, j);intR = C.R + brightness;intG = C.G + brightness;intB = c.b + brightness;if(R <0* Q =1; if(R >255* Q =255; if(G <0) G =1; if(G >255) G =255; if(B <0* A =1; if(B >255* A =255; //re-set pixel colorTmp. SetPixel (i, J, Color.FromArgb (byte) R, (byte) G, (byte) (B)); } } return(BITMAP) tmp. Clone (); } }
Change Picture brightness