Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Value does not come out right.

C#
Bitmap b = (Bitmap)pictureBox2.Image;
if (e.X >= 0 && e.X <= b.Width && e.Y >= 0 && e.Y <= b.Height)
{
   Color c = b.GetPixel(e.X, e.Y);
   mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString()
                 + " B : " + c.B.ToString();
   pictureBox3.BackColor = Color.FromArgb(c.R, c.B, c.G);
}

Real differs from the value

[Updated]
C#
Bitmap b = (Bitmap)pictureBox2.Image;
if (e.X >= 0 && e.X <= b.Width && e.Y >= 0 && e.Y <= b.Height)
{
Color c = b.GetPixel(e.X, e.Y);
mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString()
+ " B : " + c.B.ToString();
pictureBox3.BackColor = Color.FromArgb(c.R, c.B, c.G);
}


Appears a different color
pictureBox3 A different color seems to
Posted
Updated 20-Dec-11 8:24am
v4
Comments
CPallini 20-Dec-11 13:50pm    
Please detail your question: state what is the expected behaviour and what is the observed one.

1 solution

GetPixel returns a Color object. Why don't you just do this:

C#
pictureBox3.BackColor = c;
 
Share this answer
 
Comments
devil1852 20-Dec-11 14:14pm    
Appears a different color

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900