画布和位图
我有一个画布,我正在其中绘制位图并使用 onTouchEvent 方法移动该位图。我的问题是,我移动的位图有时会超出画布区域,那么如何解决与画布边界相关的问题。请帮助我解决这个问题,并提前致谢。
I have a canvas and I am drawing bitmap into it and moving that bitmap using onTouchEvent method. My problem is that the bitmap I move sometimes go out of the canvas region so how to solve this problem related to boundry of canvas. Please help me out on this and Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您在屏幕上移动手指时,您可以设置位图的 x,y 绘图坐标。由于您可以通过 onSizeChanged 方法知道画布的大小,因此您只需要编写一个 if 语句,仅当手指位于您想要的区域内时,该语句才会更改该位图的绘制坐标。
When you move the finger over the screen, you set the x,y drawing coordinates for your bitmap. Since you can know the size of the canvas from onSizeChanged method, you just need to make an if statement which will change the drawing coordinates of this bitmap only if the finger is within the area you want.
根据您的算法计算出的当前位置和基准位置的距离,您可以解决这个问题。这只是你的算法问题。
From the distance of current position and the base position calculate from your algorithm, you could able to manage this problem. It's only your algorithm problem.