I'm having problem with lightening picture. I know I could do this by increasing/decreasing pixel's values, however it's not what I'm looking for. I've been told that there's a way that do not require to iterate through all pixels and that it is much faster. How to do this? Thanks.
-
Use a library for it? Have you searched a Little? If you use WPF, I am sure there is something you can do. – bash.d May 13 '13 at 12:49
-
I'm using windows forms. – Patryk May 13 '13 at 12:50
-
2Maybe overlay a semi-transparent element over the picture? – David May 13 '13 at 12:51
-
3@David my thoughts too, `FillRectangle` with a white color and alpha should do the trick. – C.Evenhuis May 13 '13 at 12:52
-
1@Patryk Windows Forms was not made for this. Look for an external library that handles this... – bash.d May 13 '13 at 12:52
3 Answers
To lighten an image, you can apply a white haze over it:
Bitmap bmp = new Bitmap(@"Image.png");
Rectangle r = new Rectangle(0, 0, bmp.Width, bmp.Height);
alpha = 128
using (Graphics g = Graphics.FromImage(bmp)) {
using (Brush cloud_brush = new SolidBrush(Color.FromArgb(alpha, Color.White))) {
g.FillRectangle(cloud_brush, r);
}
}
bmp.Save(@"Light.png");
The alpha value can range from 0 to 255. 0 means that the effect is completely transparent resulting in the original image. 255 means that the effect is completely opaque resulting in a solid white rectangle. Here, the effect is shown with 128.
To darken an image, you can apply a black haze over it:
Bitmap bmp = new Bitmap(@"Image.png");
Rectangle r = new Rectangle(0, 0, bmp.Width, bmp.Height);
alpha = 128
using (Graphics g = Graphics.FromImage(bmp)) {
using (Brush cloud_brush = new SolidBrush(Color.FromArgb(alpha, Color.Black))) {
g.FillRectangle(cloud_brush, r);
}
}
bmp.Save(@"Dark.png");
The alpha value can range from 0 to 255. 0 means that the effect is completely transparent resulting in the original image. 255 means that the effect is completely opaque resulting in a solid black rectangle. Here, the effect is shown with 128.

- 521
- 5
- 11
You use the ColorMatrix class in System.Drawing code to apply color transformations in a highly optimized way. Effects like brightness and contrast changes are directly supported. This web page shows you what the matrix should look like.

- 922,412
- 146
- 1,693
- 2,536
To change a pictures brightness, you always have to change each pixel (if it's not a vector based graphic). iterating through the all pixels should be the only way I think. Maybe there is a framework which does the work for you. or you can look for a fast algorithm which combines a matrix of pixels to a subpixel. all in all there are many possibilitys. image processing is a complex topic.
you can find a few examples here: http://www.authorcode.com/making-image-editing-tool-in-c-brightness-of-an-image/

- 11
- 3