Color Matrix rounding error

G

Guest

I have a black and white bitmap in my app. White is transparent and the
black needs to be converted to a different color.

To manage this, I've created a ColorMatrix as follows:

Color sortArrowColor_ = Color.FromArgb(184, 192, 201);
float r = (float)sortArrowColor_.R / 255F;
float g = (float)sortArrowColor_.G / 255F;
float b = (float)sortArrowColor_.B / 255F;
float[][] ptsArray ={
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {r, g, b, 0, 1}};

The sortArrowColor represents the color I'm trying to achieve for the black.

The result I get however, is 184, 192, 200

I know it sounds trivial, but in this case, my client has very exacting
standards that must be met and this will fail to pass the testing phase. Is
there any way to correct this?

Pete
 
B

Bob Powell [MVP]

It's odd that the blue should round and not the red or the green.

You could try manually changing the colours using LockBits and manipulating
the pixels directly.

The GDI+ FAQ has an article on using LockBits

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

Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
 
F

Francois Beaussier [MVS]

pdavis68 wrote :
I have a black and white bitmap in my app. White is transparent and the
black needs to be converted to a different color.

To manage this, I've created a ColorMatrix as follows:

Color sortArrowColor_ = Color.FromArgb(184, 192, 201);
float r = (float)sortArrowColor_.R / 255F;

float r = ((float) sortArrowColor_.R + 0.5F) / 255F;
float g = (float)sortArrowColor_.G / 255F;

float g = ((float) sortArrowColor_.G + 0.5F) / 255F;
float b = (float)sortArrowColor_.B / 255F;

float b = ((float) sortArrowColor_.B + 0.5F) / 255F;

Does it make things better ?
 
G

Guest

Well, I figured out the problem. I'm a complete knucklehead. My video driver
was set for 16-bit color. ARGH.. I spent hours struggling trying to figure
out why it wouldn't spit out an odd-numbered color. As soon as I switched to
32-bit, it worked perfectly. Sorry to waste peoples' time.

Pete

Bob Powell said:
It's odd that the blue should round and not the red or the green.

You could try manually changing the colours using LockBits and manipulating
the pixels directly.

The GDI+ FAQ has an article on using LockBits

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

Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41





I have a black and white bitmap in my app. White is transparent and the
black needs to be converted to a different color.

To manage this, I've created a ColorMatrix as follows:

Color sortArrowColor_ = Color.FromArgb(184, 192, 201);
float r = (float)sortArrowColor_.R / 255F;
float g = (float)sortArrowColor_.G / 255F;
float b = (float)sortArrowColor_.B / 255F;
float[][] ptsArray ={
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {r, g, b, 0, 1}};

The sortArrowColor represents the color I'm trying to achieve for the black.

The result I get however, is 184, 192, 200

I know it sounds trivial, but in this case, my client has very exacting
standards that must be met and this will fail to pass the testing phase. Is
there any way to correct this?

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top