画布绘图和居中缩放
我正在使用 Google 教程为我的画布实现缩放功能。我正在画布上绘制多个项目,并且可以通过 Canvas.translate(dx,dy)
将其与项目一起移动。为了让我确定画布平移后是否触摸了这些项目,我采用了用于 Canvas.translate(dx,dy) 的画布偏移量并减去触摸位置。一旦我在图片中引入缩放,它就会变得有点棘手。如果我使用 Canvas.scale(sx,sy) 并执行 (touchX-offsetX)/scaleFactor ,则缩放后触摸位置的转换效果完美。但是,如果包含枢轴位置 Canvas.scale(sx,sy,px,py)
上面的代码将不起作用。作为触摸翻译的一部分,我该如何考虑枢轴位置?我通过执行以下操作来设置我的枢轴位置,
public boolean onScaleBegin(ScaleGestureDetector detector) {
mScaleX = detector.getFocusX();
mScaleY = detector.getFocusY();
return true;
}
任何帮助将不胜感激。
I'm playing with a Google tutorial to implement zooming capabilities to my canvas. I'm drawing several items onthe canvas and I'm able to move it via Canvas.translate(dx,dy)
along with the items. In order for me to determine if these items are touched after the canvas translation, I take the canvas offset used for Canvas.translate(dx,dy)
and subtract the touch position. Once I introduce scaling into the picture, it get's a little tricky. If I use Canvas.scale(sx,sy)
and do (touchX-offsetX)/scaleFactor
the translation of the touch position after the scale works perfect. However, if include a pivot position Canvas.scale(sx,sy,px,py)
the code above those not work. How do I go about factoring in the pivot position as a part of my touch translation? I set my pivot position by doing the following,
public boolean onScaleBegin(ScaleGestureDetector detector) {
mScaleX = detector.getFocusX();
mScaleY = detector.getFocusY();
return true;
}
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的解决方案
}
Simple solution
}