Advertisement
Guest User

Luminozitate

a guest
Jul 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. imi1 = pictureBox2.Image;
  2. ImUndo = imi1;
  3. Bitmap originalImage = new Bitmap(imi1.Width, imi1.Height);
  4. Graphics gi = Graphics.FromImage(originalImage);
  5. gi.DrawImage(imi1, 0, 0);
  6. Bitmap adjustedImage = originalImage;
  7. float brightness = 1.0f; // no change in brightness
  8. float contrast = Convert.ToSingle(numericUpDown1.Value); // twice the contrast
  9. float gamma = 1.0f; // no change in gamma
  10.  
  11. float adjustedBrightness = brightness - 1.0f;
  12. // create matrix that will brighten and contrast the image
  13. float[][] ptsArray ={
  14. new float[] {contrast, 0, 0, 0, 0}, // scale red
  15. new float[] {0, contrast, 0, 0, 0}, // scale green
  16. new float[] {0, 0, contrast, 0, 0}, // scale blue
  17. new float[] {0, 0, 0, 1.0f, 0}, // don't scale alpha
  18. new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}};
  19. System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
  20. imageAttributes.ClearColorMatrix();
  21. imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
  22. imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);
  23. Graphics g = Graphics.FromImage(adjustedImage);
  24. g.DrawImage(originalImage, new Rectangle(0, 0, adjustedImage.Width, adjustedImage.Height)
  25. , 0, 0, originalImage.Width, originalImage.Height,
  26. GraphicsUnit.Pixel, imageAttributes);
  27. pictureBox2.Image = adjustedImage;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement