[lnkForumImage]
TotalShareware - Download Free Software

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


 

monroe

11/17/2004 12:25:00 PM

Hi all,

Ok, this is possibly a newbie question, but I'm kind of a newbie
anyway, so here it goes :)

I have a Bitmap I need to control through a ControlMatrix. I can
easily make changes to the brightness or contrast of the picture. If I
got it right, being X the elements I need to change, it goes...

1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
X X X 0 1

for brightness, and

X 0 0 0 0
0 X 0 0 0
0 0 X 0 0
0 0 0 1 0
0 0 0 0 1

for Contrast. The problem comes with the Saturation...elements that
change are

X X X 0 0
X X X 0 0
X X X 0 0
0 0 0 1 0
0 0 0 0 1

I can also change the Saturation with no problems at all.

Trouble comes if I try to change the Contrast _and_ Saturation of the
bitmap...I'm guessing it's because of the elements (0,0) (1,1) and
(2,2) affecting both Contrast and Saturation when I make a change for
one of them, but the fact is I'm getting some weird side effects :D
The bitmap changes but definitely not how it's supposed to.

This is because I'm using just one Matrix, where I update all desired
changes and then apply it to the original bitmap to get the result I
show to the user.

For example, I could DrawImage with a ColorMatrix that looks like
this...

3 0 0 0 0
0 3 0 0 0
0 0 3 0 0
0 0 0 1 0
2 2 2 0 1

to change both Contrast and Brightness at the very same time.

I do it this way after trying a different view; saving the result
bitmap after a transformation, generating a new identity matrix,
setting the new desired transformation into it and then applying it to
the bitmap to get a new result. This system obviously had undesireable
results; if I, for example, set the contrast to 0 and then to 1 again
I've lost the original bitmap into a black one.

So the question is (and probably the answer is easy, I'm way too bad
in algebra for this, I'm missing something or I'm simply a noob)...How
can I set the contrast of a bitmap to A and it's color Saturation to B
using only one ColorMatrix and one DrawImage method?

Thanks all
2 Answers

Bob Powell

11/17/2004 1:01:00 PM

0

There is a great example of how to perform these sorts of operations here...

http://www.codeguru.com/Cpp/G-M/gdi/gdi/article...

The application is built for MFC and uses the GDI+ dll but the principles
can easily be converted to work with C# or VB.NET

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





"Samuel Caparros" <monroe@ciudadparagon.com> wrote in message
news:1ff2dcdd.0411170425.7d59a05b@posting.google.com...
> Hi all,
>
> Ok, this is possibly a newbie question, but I'm kind of a newbie
> anyway, so here it goes :)
>
> I have a Bitmap I need to control through a ControlMatrix. I can
> easily make changes to the brightness or contrast of the picture. If I
> got it right, being X the elements I need to change, it goes...
>
> 1 0 0 0 0
> 0 1 0 0 0
> 0 0 1 0 0
> 0 0 0 1 0
> X X X 0 1
>
> for brightness, and
>
> X 0 0 0 0
> 0 X 0 0 0
> 0 0 X 0 0
> 0 0 0 1 0
> 0 0 0 0 1
>
> for Contrast. The problem comes with the Saturation...elements that
> change are
>
> X X X 0 0
> X X X 0 0
> X X X 0 0
> 0 0 0 1 0
> 0 0 0 0 1
>
> I can also change the Saturation with no problems at all.
>
> Trouble comes if I try to change the Contrast _and_ Saturation of the
> bitmap...I'm guessing it's because of the elements (0,0) (1,1) and
> (2,2) affecting both Contrast and Saturation when I make a change for
> one of them, but the fact is I'm getting some weird side effects :D
> The bitmap changes but definitely not how it's supposed to.
>
> This is because I'm using just one Matrix, where I update all desired
> changes and then apply it to the original bitmap to get the result I
> show to the user.
>
> For example, I could DrawImage with a ColorMatrix that looks like
> this...
>
> 3 0 0 0 0
> 0 3 0 0 0
> 0 0 3 0 0
> 0 0 0 1 0
> 2 2 2 0 1
>
> to change both Contrast and Brightness at the very same time.
>
> I do it this way after trying a different view; saving the result
> bitmap after a transformation, generating a new identity matrix,
> setting the new desired transformation into it and then applying it to
> the bitmap to get a new result. This system obviously had undesireable
> results; if I, for example, set the contrast to 0 and then to 1 again
> I've lost the original bitmap into a black one.
>
> So the question is (and probably the answer is easy, I'm way too bad
> in algebra for this, I'm missing something or I'm simply a noob)...How
> can I set the contrast of a bitmap to A and it's color Saturation to B
> using only one ColorMatrix and one DrawImage method?
>
> Thanks all


monroe

11/18/2004 11:00:00 AM

0

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:<e1HBRWKzEHA.1452@TK2MSFTNGP11.phx.gbl>...
> There is a great example of how to perform these sorts of operations here...
>
> http://www.codeguru.com/Cpp/G-M/gdi/gdi/article...
>
> The application is built for MFC and uses the GDI+ dll but the principles
> can easily be converted to work with C# or VB.NET
>
> --
> 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.

Thanks a lot, Bob, that did the trick :)

So, matrices multiplying...I'm sure I could do some funny things with this...
:)