iPhone - 以像素和屏幕分辨率为单位的 CGPoint 距离

发布于 2024-11-25 14:09:34 字数 981 浏览 2 评论 0原文

我将此代码放入 - (void)drawMapRect:(MKMapRect)mapRect ZoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context 方法(放入 MKOverlayView 子类)中,以防止绘制小于地图覆盖上 10 像素长:

            CGPoint origin = [self pointForMapPoint:poly.points[0]];
            CGPoint lastPoint = origin;

            CGContextMoveToPoint(context, origin.x, origin.y);

            for (int i=1; i<poly.pointCount; i++) {
                CGPoint point = [self pointForMapPoint:poly.points[i]];

                CGFloat xDist = (point.x - lastPoint.x);
                CGFloat yDist = (point.y - lastPoint.y);
                CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist)) * zoomScale;

                if (distance >= 10.0) {
                    lastPoint = point;
                    CGContextAddLineToPoint(context, point.x, point.y);
                }
            }

测试 >= 10.0 会考虑屏幕分辨率吗,或者我可以介绍一些 [UIScreen mainScreen].scale 参数?

I have this code into the - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context method (into a MKOverlayView subclass) to prevent drawing segments that are less than 10 pixels long on a map overlay :

            CGPoint origin = [self pointForMapPoint:poly.points[0]];
            CGPoint lastPoint = origin;

            CGContextMoveToPoint(context, origin.x, origin.y);

            for (int i=1; i<poly.pointCount; i++) {
                CGPoint point = [self pointForMapPoint:poly.points[i]];

                CGFloat xDist = (point.x - lastPoint.x);
                CGFloat yDist = (point.y - lastPoint.y);
                CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist)) * zoomScale;

                if (distance >= 10.0) {
                    lastPoint = point;
                    CGContextAddLineToPoint(context, point.x, point.y);
                }
            }

will the test >= 10.0 will take care about the screen resolution, or may I introduce some [UIScreen mainScreen].scale parameter ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

飘过的浮云 2024-12-02 14:09:34

我相信 test >= 10.0 没有考虑屏幕分辨率。苹果公司的大部分绘图算法都使用“点”而不是像素——这样,与普通显示器相比,视网膜显示器的代码就不必改变。

如果您想绘制宽度仅为 10.0 像素的内容,则需要考虑屏幕分辨率;但是,如果您这样做,您将必须编写方法来支持视网膜显示和正常显示。

I believe that test >= 10.0 does not take into account the screen resolution. Apple does most of their drawing arithmetic using "points" instead of pixels- that way code does not have to change for a retina display compared to a normal display.

If you want to draw something just 10.0 pixels wide, you will need to take into account the screen resolution; however, if you do this you'll have to write the method to support both retina display and normal display.

七度光 2024-12-02 14:09:34

这取决于图形上下文的配置方式。如果这是在 UIView 绘图代码中,则视图的比例因子(自动设置)将处理此问题,如果您正在绘制位图上下文,则必须手动执行此操作。

It depends on how the graphics context is configured. If this is in UIView drawing code, the view's scale factor (which is set automatically) will take care of this, if you're drawing into a bitmap context, you have to do it manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文