How to determine pixel hit in an image

3 posts, 0 answers
  1. Elliotte
    Elliotte avatar
    3 posts
    Member since:
    Nov 2012

    Posted 15 Apr 2013 Link to this post

    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. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 18 Apr 2013 Link to this post

    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.
  3. DevCraft banner
  4. Elliotte
    Elliotte avatar
    3 posts
    Member since:
    Nov 2012

    Posted 23 Apr 2013 Link to this post

    Victor,

    Thanks, that did help.  I had to use the PanZoom loaded event instead of the MainPage loaded event, however.  Otherwise it returned null. 
Back to Top