[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

brightness adjusting on black & white images vb.net

marfi95

1/6/2005 4:47:00 AM

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


7 Answers

Bob Powell

1/6/2005 9:55:00 AM

0

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/tips...

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

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





<marfi95@yahoo.com> wrote in message
news:tvfpt05bp62n1ilrqpbt1iteli0dmvjeua@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
>
>


C-Services Holland b.v.

1/6/2005 12:32:00 PM

0

marfi95@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.

marfi95

1/6/2005 1:12:00 PM

0

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

Bob Powell

1/6/2005 2:16:00 PM

0

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/tips...

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

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





<marfi95@yahoo.com> wrote in message
news:f7eqt0pch3hpcnrgpbou3uqk7ks48i701j@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
>


marfi95

1/6/2005 3:26:00 PM

0

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.

Bob Powell

1/6/2005 11:53:00 PM

0

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/tips...

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

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





<marfi95@yahoo.com> wrote in message
news:1105025165.721698.243520@z14g2000cwz.googlegroups.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.
>


marfi95

1/7/2005 4:41:00 AM

0

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/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> <marfi95@yahoo.com> wrote in message
> news:1105025165.721698.243520@z14g2000cwz.googlegroups.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.
> >