How to find out where on my image I touched if I moved and resized my image with a pinch, drag and zoom

I have an image, I use it as an image map. If the image was fixed, then there would be no problem, but I need to zoom in and drag this image, and also get and use the coordinates of where the image was clicked.

Do I need to track how much this image has been moved and changed, or can I get the 0x0-point of my image (upper left corner of my image).

Is there any other way to do this

I have to add that I based image processing on this excellent tutorial http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2/1747?tag=rbxccnbzd1

+4
source share
1 answer

You can get the point using the same transformation matrix that applies to the image. You want to convert the point between the screen coordinate system to the image coordinate system by changing the effect of the original matrix.

In particular, you want to convert the x, y coordinates, where the user clicked on the screen at the corresponding point in the original image, using the inverse matrix that was used to convert the image to the screen.

A bit of pseudo-code assuming a matrix contains a transform that was applied to the image:

// pretend user clicked the screen at {20.0, 15.0} float x = 20.0; float y = 15.0; float[] pts[2]; pts[0] = x; pts[1] = y; // get the inverse of the transformation matrix // (a matrix that transforms back from destination to source) Matrix inverse = new Matrix(); if(matrix.invert(inverse)) { // apply the inverse transformation to the points inverse.mapPoints(pts); // now pts[0] is x relative to image left // pts[1] is y relative to image top } 
+2
source

Source: https://habr.com/ru/post/1396510/


All Articles