如何绘制一条直线,并知道该线的长度(以像素为单位)?
我正在开发一款 iPad 应用程序,所要求的功能之一是能够测量图像。考虑到 iPad 屏幕的分辨率为 132ppi,实现这一点似乎相当简单。
但是如何在iPad上画直线呢?有没有最好的图书馆?我需要核心动画、open gl 或quartz 吗?我没有任何画画的经验,所以如果有人能像“这样做”,我就会去弄清楚如何做。我想让用户只能画一条直线,然后当他们完成时,我需要知道这条线有多少像素长。
请帮忙。谢谢
编辑我忘了说清楚,我希望能够做到这一点,以便随着用户的走动而绘制线条。所以他们把手指放下来,然后可能会出现一个小点,然后当他们拖动时,线就会停留,当他们停下来时,线就完成了。
I am working on an iPad app, and one of the features that has been requested is the ability to make measurements of an image. With the knowledge that the iPad screen has a 132ppi resolution, it seems as though it will be quite simple to implement this.
But how can I draw a straight line on the iPad? Is there a library that is best? Is core animation, open gl, or quartz what I need? I don't have any experience drawing anything, so if someone can just be like "do this", I'll go figure out how to do it. I want to make it so the user can't draw anything but a straight line, and then when they are done, I need to know how many pixels long the line is.
Please help. Thanks
EDIT I forgot to make this clear, I would like to be able to make it so the line is drawn as the user goes. So they put the finger down, and then maybe a little dot appears, then as they drag, the line gets linger, and when they stop, the line is done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅此答案:
如何绘制iPhone 上的线?
此外,要获取长度,请实现 TouchBegan 和 TouchEnded,记录两个 CGPoint 并计算增量。
Please see this answer:
How do I draw a line on the iPhone?
Also, to get the length, implement touchesBegan and touchesEnded, record both CGPoints and calculate the delta.
距离公式
在代码中:
The distance formula
In code: