How to get pixel coordinates and RGB values when cursor moves over an image?

M

moss

Hi,
I have a simple custom control (inherits from UserControl) that
displays an image (not a pictureBox). My goal is to get the pixel
coordinates and the RGB values of a pixel that the mouse is hovering
over and display that information in the status bar of my application.
Since this is an image viewing application, the image displayed on the
control is always changing, and there are two viewing modes:
1. the image streches the boundaries of the control (enables
autoscroll if necessary) to fit its contents.
2. if the image size iz bigger than the clientsize of the control, the
image is resized to fit the current size of the control, leaving some
blank space around itself.
So I think you can see my point here... how can I get the pixel
coordinates and values when the mouse hovers the image, not over the
whole control? It seems to me I'll somehow have to always keep on
track of the area on the control containing the image that will handle
the MouseMove event or something like that... Please help if there's
an easier solution.

Marko
 
P

Peter Duniho

moss said:
[...]
So I think you can see my point here... how can I get the pixel
coordinates and values when the mouse hovers the image, not over the
whole control? It seems to me I'll somehow have to always keep on
track of the area on the control containing the image that will handle
the MouseMove event or something like that... Please help if there's
an easier solution.

Your proposal sounds easy enough to me. In any case, you have to have
_some_ way of comparing the mouse position to the on-screen display of
the image, and then calculating the equivalent portion of the image.
This necessarily means using that information somehow, whether you store
it for easy access or recalculate it each time.

Of course, if the image is scaled down, not displayed at a 1-to-1 pixel
scaling, obviously a given mouse coordinate will map to something larger
than a single pixel in the original image, and you'll have to just pick
the nearest pixel based on whatever criteria you like.

Pete
 
A

ateendra singh

hi, if you have a solution, i have an exactly similar application. please share with me



moss wrote:

How to get pixel coordinates and RGB values when cursor moves over an image?
08-Dec-09

Hi
I have a simple custom control (inherits from UserControl) tha
displays an image (not a pictureBox). My goal is to get the pixe
coordinates and the RGB values of a pixel that the mouse is hoverin
over and display that information in the status bar of my application
Since this is an image viewing application, the image displayed on th
control is always changing, and there are two viewing modes
1. the image streches the boundaries of the control (enable
autoscroll if necessary) to fit its contents
2. if the image size iz bigger than the clientsize of the control, th
image is resized to fit the current size of the control, leaving som
blank space around itself
So I think you can see my point here... how can I get the pixe
coordinates and values when the mouse hovers the image, not over th
whole control? It seems to me I will somehow have to always keep o
track of the area on the control containing the image that will handl
the MouseMove event or something like that... Please help if there i
an easier solution

Marko

Previous Posts In This Thread:

How to get pixel coordinates and RGB values when cursor moves over an image?
Hi
I have a simple custom control (inherits from UserControl) tha
displays an image (not a pictureBox). My goal is to get the pixe
coordinates and the RGB values of a pixel that the mouse is hoverin
over and display that information in the status bar of my application
Since this is an image viewing application, the image displayed on th
control is always changing, and there are two viewing modes
1. the image streches the boundaries of the control (enable
autoscroll if necessary) to fit its contents
2. if the image size iz bigger than the clientsize of the control, th
image is resized to fit the current size of the control, leaving som
blank space around itself
So I think you can see my point here... how can I get the pixe
coordinates and values when the mouse hovers the image, not over th
whole control? It seems to me I will somehow have to always keep o
track of the area on the control containing the image that will handl
the MouseMove event or something like that... Please help if there i
an easier solution

Marko

moss wrote:Your proposal sounds easy enough to me.
moss wrote

Your proposal sounds easy enough to me. In any case, you have to hav
_some_ way of comparing the mouse position to the on-screen display o
the image, and then calculating the equivalent portion of the image
This necessarily means using that information somehow, whether you stor
it for easy access or recalculate it each time

Of course, if the image is scaled down, not displayed at a 1-to-1 pixe
scaling, obviously a given mouse coordinate will map to something large
than a single pixel in the original image, and you will have to just pic
the nearest pixel based on whatever criteria you like

Pete


Submitted via EggHeadCafe - Software Developer Portal of Choice
Win A Free License of SandDock for Silverlight
http://www.eggheadcafe.com/tutorial...free-license-of-sanddock-for-silverlight.aspx
 

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

Top