如何在android中绘制沿特定路径(弧线)移动的位图?
我正在尝试创建一个自定义组件。我有一个位图图像作为标记,它必须沿弧线方向行进。标记的位置是使用用户的触摸来定位的。 即使用户尝试将标记拖动到圆弧之外,这也不应该是可能的。
现在在onDraw
中使用Canvas
我已经绘制了一个弧线和标记位图图像。但不知道如何使位图仅遵循该弧线。
I am trying to create a custom component.I have a bitmap image as marker and it has to travel in an arc direction.The position of the marker is located using the user's touch.
Even if the user try to drag the marker outside the arc,it should not be possible.
Now using Canvas
in onDraw
i have drawn an arc and marker Bitmap image.But don't know how to make the bitmap to follow only that arc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要编写一个函数来查找弧上距用户触摸点距离最近的点。弧上的那个点就是您要绘制图像的位置。
现在,该计算很大程度上取决于您如何将弧表示为数学函数。这是“解析几何”的主题
,但不太准确和更简单的方法是(如果滑动不需要平滑),如果你在弧上选择一些样本点并仅使用这些点来计算这个距离,最后你选择距离最小的那个。选择的点越多,“滑动”就越顺畅。
You need to write a function that finds a point on your arc that has the least distance to the point where user touched. That point on your arc is the place where you want to draw your image.
Now, that calculation very much depends on how you represent your arc as a mathematical function. And that is a subject of "Analytic Geometry"
But a less accurate and simpler way would be(if the sliding doesn't need to be smooth), if you choose some sample points on your arc and use only those points to calculate this distance, and finally you choose the one with the least distance. The more points you choose the smoother it will "slide".