By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

brightness adjusting on black & white images vb.net

P: n/a
I'm trying to implement some code in vb.net to allow the user to
adjust the brightness or contrast on an image (through the use of a
slider) that is already black & white in the bitmap. I have tried
to use the colormatrix and even down to the pixel using GetPixel and
SetPixel in system.drawing, but I'm really not up on using gdi+ and
haven't really gotten anywhere. I've seen some examples for VB6, but
I need vb.net.

I know that all the pixels are either 255 or 0 already since its black
and white, but if you are adusting the brightness, how do you decide
which pixels to turn white or black based on how much the user wants
to brighten/darken. I've got code to read & set each pixel, but I
just dont know what to use to decide what to set the new pixel to.

If you someone could post some code or point me to a good example that
explains whats going on, I would be most appreciative.

Thanks,
Mark
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
The GDI+ FAQ has articles on this. Search bobpowell.net for ColorMatrix

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

<ma*****@yahoo.com> wrote in message
news:tv********************************@4ax.com...
I'm trying to implement some code in vb.net to allow the user to
adjust the brightness or contrast on an image (through the use of a
slider) that is already black & white in the bitmap. I have tried
to use the colormatrix and even down to the pixel using GetPixel and
SetPixel in system.drawing, but I'm really not up on using gdi+ and
haven't really gotten anywhere. I've seen some examples for VB6, but
I need vb.net.

I know that all the pixels are either 255 or 0 already since its black
and white, but if you are adusting the brightness, how do you decide
which pixels to turn white or black based on how much the user wants
to brighten/darken. I've got code to read & set each pixel, but I
just dont know what to use to decide what to set the new pixel to.

If you someone could post some code or point me to a good example that
explains whats going on, I would be most appreciative.

Thanks,
Mark

Nov 21 '05 #2

P: n/a
ma*****@yahoo.com wrote:
I'm trying to implement some code in vb.net to allow the user to
adjust the brightness or contrast on an image (through the use of a
slider) that is already black & white in the bitmap. I have tried
to use the colormatrix and even down to the pixel using GetPixel and
SetPixel in system.drawing, but I'm really not up on using gdi+ and
haven't really gotten anywhere. I've seen some examples for VB6, but
I need vb.net.

I know that all the pixels are either 255 or 0 already since its black
and white, but if you are adusting the brightness, how do you decide
which pixels to turn white or black based on how much the user wants
to brighten/darken. I've got code to read & set each pixel, but I
just dont know what to use to decide what to set the new pixel to.

If you someone could post some code or point me to a good example that
explains whats going on, I would be most appreciative.

Thanks,
Mark


If your values are at 0 or 255 you've got maximum contrast. You can't
decrease contrast for just a few pixels since there would be no way to
determine what pixels should remain white/black and what pixels should
turn some shade of grey. You could only decrease the contrast by
bringing the 0 and 255 values closer together, but don't expect some
gradient to appear.

--
Rinze van Huizen
C-Services Holland b.v.
Nov 21 '05 #3

P: n/a
So you can use the ColorMatrix to adjust images even if they are
already black and white ?

On Thu, 6 Jan 2005 10:55:00 +0100, "Bob Powell [MVP]"
<bob@_spamkiller_bobpowell.net> wrote:
The GDI+ FAQ has articles on this. Search bobpowell.net for ColorMatrix


Nov 21 '05 #4

P: n/a
Of course. The matrix doesn't care what values the RGB elements are or if
they're the same, which is all a grayscale is, equal R, G and B.

You can still change the brightness and contrast using the matrix. You can't
put saturation back in though. That's like trying to put the air back in a
burst balloon.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

<ma*****@yahoo.com> wrote in message
news:f7********************************@4ax.com...
So you can use the ColorMatrix to adjust images even if they are
already black and white ?

On Thu, 6 Jan 2005 10:55:00 +0100, "Bob Powell [MVP]"
<bob@_spamkiller_bobpowell.net> wrote:
The GDI+ FAQ has articles on this. Search bobpowell.net for ColorMatrix

Nov 21 '05 #5

P: n/a
Thanks Bob.

I took your example of adjusting the contrast (the one with
ImageContrast as the namespace) and ran against one of my test images.
The problem was the image was able to get darker, but never got any
lighter (even when moving the trackbar all the way over). Let me
explain what I'm doing. The images we display are coming out of a
check scanner for our customers. We allow them to rescan them at
lighter/darker contrast values, but that forces them to go through the
scanner again which is not a real fast device. So what I wanted to do
is let them adjust the original image directly on the screen through
the use of a trackbar and not require them to go through the scanner
again.

The images are coming out of the scanner in a 1bpp indexed pixel format
- black/white ?

Any ideas why it wouldn't get any darker. Is there a better way to do
it.

Many thanks.

Nov 21 '05 #6

P: n/a
I guess the reason is because you're altering the original image, not a copy
of it.

You need to copy the original to the new setting every time, don't change an
image and then try to adjust *its* contrast / brightness later. It's a
classic degradation problem.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

<ma*****@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks Bob.

I took your example of adjusting the contrast (the one with
ImageContrast as the namespace) and ran against one of my test images.
The problem was the image was able to get darker, but never got any
lighter (even when moving the trackbar all the way over). Let me
explain what I'm doing. The images we display are coming out of a
check scanner for our customers. We allow them to rescan them at
lighter/darker contrast values, but that forces them to go through the
scanner again which is not a real fast device. So what I wanted to do
is let them adjust the original image directly on the screen through
the use of a trackbar and not require them to go through the scanner
again.

The images are coming out of the scanner in a 1bpp indexed pixel format
- black/white ?

Any ideas why it wouldn't get any darker. Is there a better way to do
it.

Many thanks.

Nov 21 '05 #7

P: n/a
That makes sense. Yea, I am applying the new user settings to the
"already adjusted" image, when I should be going back to the original
each time.

I'll try it when I get in the office. Thanks.
Bob Powell [MVP] wrote:
I guess the reason is because you're altering the original image, not a copy of it.

You need to copy the original to the new setting every time, don't change an image and then try to adjust *its* contrast / brightness later. It's a classic degradation problem.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

<ma*****@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks Bob.

I took your example of adjusting the contrast (the one with
ImageContrast as the namespace) and ran against one of my test images. The problem was the image was able to get darker, but never got any
lighter (even when moving the trackbar all the way over). Let me
explain what I'm doing. The images we display are coming out of a
check scanner for our customers. We allow them to rescan them at
lighter/darker contrast values, but that forces them to go through the scanner again which is not a real fast device. So what I wanted to do is let them adjust the original image directly on the screen through the use of a trackbar and not require them to go through the scanner again.

The images are coming out of the scanner in a 1bpp indexed pixel format - black/white ?

Any ideas why it wouldn't get any darker. Is there a better way to do it.

Many thanks.


Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.