简体   繁体   English

canvas.scale之后的位图坐标

[英]Bitmap coordinates after canvas.scale

I need help at getting the correct coordinates when touching the canvas. 在触摸画布时,我需要帮助以获取正确的坐标。

I have an image that is 1240x1756 我的图片是1240x1756

The user can scroll around on this bitmap. 用户可以在该位图上滚动。 It is the bitmap attached to the canvas. 它是附加到画布的位图。 I do this by translating the canvas. 我通过翻译画布来做到这一点。 canvas.translate() canvas.translate()

The user can also place a new bitmap and move that anywhere around on the canvas. 用户还可以放置新的位图并将其移动到画布上的任何位置。 up to 256x256. 最高256x256。

Up until this point I have no problem calculating the touch coordinates at scale factor of 1.0. 到目前为止,在比例因子为1.0的情况下计算触摸坐标没有问题。 I take the screen touch coords and add the offset of the image and then check to see if the 256x256 moveable bitmap intersects the touch coords. 我获取屏幕触摸坐标并添加图像的偏移量,然后检查256x256可移动位图是否与触摸坐标相交。

However my issue is getting the correct coordinates after the canvas has been scaled. 但是我的问题是在画布缩放后获取正确的坐标。 0.1-1.0 are my minimum and maximum scaling values. 0.1-1.0是我的最小和最大缩放比例值。

Can anyone point me in the right direction for a working algorithm? 谁能为我指出正确的算法工作方向?

您应该能够将像素偏移乘以1 /比例因子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM