This is a migrated thread and some comments may be shown as answers.

How to determine pixel hit in an image

2 Answers 74 Views
PanAndZoomImage
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Elliotte
Top achievements
Rank 1
Elliotte asked on 15 Apr 2013, 07:45 AM
On the tap event of the Pan and zoom control, there is a GestureEventArg which has method called GetPosition.  I need to use the value returned by this function to determine which pixel in the image has been tapped after the image has been zoomed and panned.  Is there some algorithm I can use to determine this?  I can't figure out what the values returned by GetPosition are.

2 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 18 Apr 2013, 07:50 AM
Hello Elliotte,

PanAndZoomImage does not provide means to track pixel positions and or to edit images. The GetPosition() method returns a point in the coordinate system of the element to which you have subscribed taking into account any render transforms that you may have set. The problem in your case is that you have subscribed to PanAndZoomImage itself and not the Image element that is inside the PanAndZoomImageControl. If you get the internal image like this:

void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
    ElementTreeHelper.FindVisualDescendant<Image>(this.panAndZoom).Tap += this.Image_Tap_1;
}
and then subscribe to its Tap event, GetPosition() will return the correct pixel. Keep in mind that the ControlTemplate of PanAndZoomImage must be applied in order for FindVisualDescendant() to work, this is why it is called in the Loaded event handler of the page.

I hope this helps.

Regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Elliotte
Top achievements
Rank 1
answered on 23 Apr 2013, 06:11 AM
Victor,

Thanks, that did help.  I had to use the PanZoom loaded event instead of the MainPage loaded event, however.  Otherwise it returned null. 
Tags
PanAndZoomImage
Asked by
Elliotte
Top achievements
Rank 1
Answers by
Victor
Telerik team
Elliotte
Top achievements
Rank 1
Share this question
or