如何绘制一条直线,并知道该线的长度(以像素为单位)?

发布于 2024-11-03 11:05:38 字数 338 浏览 6 评论 0原文

我正在开发一款 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾挽 2024-11-10 11:05:38

请参阅此答案:

如何绘制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.

思念满溢 2024-11-10 11:05:38

距离公式

在代码中:

 CGFloat dx = point2.x - point1.x;
 CGFloat dy = point2.y - point1.y;
 CGFloat distance = sqrt(dx*dx + dy*dy);

The distance formula

In code:

 CGFloat dx = point2.x - point1.x;
 CGFloat dy = point2.y - point1.y;
 CGFloat distance = sqrt(dx*dx + dy*dy);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文