Touch point coordinates with respect to Image after pinch zoom

爷,独闯天下 提交于 2020-01-01 19:54:07

问题


How to calculate the coordinates with respect to image after zoom the image? To zoom the image I followed the url: https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/example/touch/TouchImageView.java.

if we touch the image at particular point before Zoom then corresponding values are

point:(3,2)
top left corner of image:(0,0)
top left corner of screen:(0,0)
scale factors:(1.25,0.98)

After zoom the image:

if we drag the image until the image top left corner coincides the screen top left corner and touch image exactly at same touch point(before pinch) then

point:(540,220)
top left corner of image:(0,0)
top left corner of screen:(0,0)
scale factors:(4.78,2.67)

if we drag the image until the image top right corner coincides with the screen top right corner and touch image exactly at same touch point(before pinch) then

point:(1080,340)
top left corner of screen:(0,0)
top left corner of image:(-2430,0)
scale factors:(4.78,2.67)

if we drag the image until the image bottom left corner coincides with the screen bottom left corner and touch image exactly at same touch point(before pinch) then

point:(670,80)
top left corner of screen:(0,0)
top left corner of image:(0,-890)
scale factors:(4.78,2.67)

if we drag the image until the image bottom right corner coincides with the screen bottom right corner and touch image exactly at same touch point(before pinch) then

point:(456,274)
top left corner of screen:(0,0)
top left corner of image:(-2430,-890)
scale factors:(4.78,2.67)

if we set the image over the screen [ not to set the any corner]

point:(743,146)
top left corner of screen:(0,0)
top left corner of image:(-1280,-423)
scale factors:(4.78,2.67)

In all the above scenarios I am getting the coordinates in touch event as

x_cord=event.getX();
y_cord=event.getY();

The touch points I am getting are with respect to the screen.

How can I calculate the touch points according to the Image?

Thanks & Regards mini.


回答1:


We can calculate by calculating relative point according to the image size

float[] values = new float[9];
matrix.getValues(values);
x_coord = ((e.getX() - values[2])*scaleX )/values[0];
y_coord= ((e.gety() - values[5])*scaleY )/ values[4];



回答2:


In my case I calculated those points as follows. This will be helpful for someone.

x = (event.getX() / values[Matrix.MSCALE_X] - (values[Matrix.MTRANS_X]/values[Matrix.MSCALE_X]));
y = (event.getY() / values[Matrix.MSCALE_Y] - (values[Matrix.MTRANS_Y]/values[Matrix.MSCALE_Y]));


来源:https://stackoverflow.com/questions/12279087/touch-point-coordinates-with-respect-to-image-after-pinch-zoom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!