Click here to Skip to main content
14,428,333 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have done a project in Visual C# Express 2010. When we move a mouse pointer on to the image and click on a image, the color under the mouse pointer would be displayed and R,G,B values can be displayed in a textbox.

But I am unable to do the same project in Silverlight Application i.e., WPF by Visual Web Developer 2010. Can anybody help me regarding this?

I can post the whole code to individual e-mail, if I get any response to this question.
Posted
Comments
Bruno Tagliapietra 22-Apr-11 10:04am
   
try sending code in a zip file at bruno.tagliapietra@gmail.com

if you're sending a whole solution folder, "Clean" away the exe files from visual studio first.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can use tooltip and bind the RGB values as tooltip text .
Can you tell which control is used for displaying the color ?
   
Comments
Member 7810323 26-Apr-11 19:56pm
   
I have used the below code.

WriteableBitmap wb = new WriteableBitmap(image1, null);
double x = e.GetPosition(this).X;
double y = e.GetPosition(this).Y;
textBox1.Text = x.ToString();
textBox2.Text = y.ToString();

int col = wb.Pixels[(int)(y * image1.Width) + (int)x];
textBox3.Text = ((col >> 16) & 0xFF).ToString() + " " +
((col >> 8) & 0xFF).ToString() + " " +
((col >> 0) & 0xFF).ToString();

Can anybody please modify this code to get the color at a particular pixel from the image. and I should be able to display the RGB values of that color too.
Rate this:
Please Sign up or sign in to vote.

Solution 2

This[^] might be possible using the WriteableBitmap class.
   
Comments
Member 7810323 26-Apr-11 19:56pm
   
I have used the below code.

WriteableBitmap wb = new WriteableBitmap(image1, null);
double x = e.GetPosition(this).X;
double y = e.GetPosition(this).Y;
textBox1.Text = x.ToString();
textBox2.Text = y.ToString();

int col = wb.Pixels[(int)(y * image1.Width) + (int)x];
textBox3.Text = ((col >> 16) & 0xFF).ToString() + " " +
((col >> 8) & 0xFF).ToString() + " " +
((col >> 0) & 0xFF).ToString();

Can anybody please modify this code to get the color at a particular pixel from the image. and I should be able to display the RGB values of that color too.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100