使用 Core Graphics 绘图在 Retina 显示屏上看起来很厚重

发布于 2024-10-21 21:18:04 字数 651 浏览 6 评论 0原文

我有一个 UIView,它从 drawRect:rect 内部绘制一个圆。在阅读了有关 Retina 显示屏的 Apple 开发信息后,似乎使用 Core Graphics 意味着绘图将自动利用更高的分辨率。然而,与徽章图标中的类似圆圈相比,这个简单的圆圈看起来相当粗。显然,我将它与具有光泽和阴影的东西进行比较,但我认为很明显我的也没有被绘制。我尝试截取苹果图标徽章和我的圆圈的屏幕截图,它们在我的 Mac 上看起来几乎相同 - 不过,当在手机上查看时,差异很明显。我在这里缺少一些简单的东西吗?

这是我在drawRect:rect中使用的绘图代码

UIBezierPath* aPath = [UIBezierPath bezierPathWithOvalInRect:
                       CGRectMake(0, 0, 22, 22)];

[[UIColor whiteColor] setStroke];
[[UIColor redColor] setFill];

CGContextRef aRef = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(aRef, 10, 10);
aPath.lineWidth = 3;
[aPath fill];
[aPath stroke];

感谢您的帮助, 抢

I have a UIView that draws a circle from inside drawRect:rect. After reading the Apple dev info on the Retina display, it seemed like using Core Graphics meant that the drawings would automatically take advantage of the higher res. This simple circle, however, looks pretty chunky as compared to a similar circle in a badge icon. Obviously I'm comparing it to something that has gloss and shadow but I think it's pretty obvious that mine is not being drawn as well. I tried taking screenshots of apple's icon badge and my circle and they look about the same on my mac - the difference is obvious when looking at each on the phone, though. Is there something simple I'm missing here?

This is the drawing code that I'm using in drawRect:rect

UIBezierPath* aPath = [UIBezierPath bezierPathWithOvalInRect:
                       CGRectMake(0, 0, 22, 22)];

[[UIColor whiteColor] setStroke];
[[UIColor redColor] setFill];

CGContextRef aRef = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(aRef, 10, 10);
aPath.lineWidth = 3;
[aPath fill];
[aPath stroke];

Thanks for any help,
Rob

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

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

发布评论

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

评论(1

粉红×色少女 2024-10-28 21:18:04

哎呀,它首先需要抗锯齿:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, YES);

我在绘制之前添加了它,然后将其设置为“否”,然后立即绘制了另一个圆圈。并排的两个圆圈表明这就是问题所在。

Oops, it needed antialiasing first:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, YES);

I added this before drawing, then set it to NO and drew another circle immediately afterward. The two circles, side by side, show that this was the problem.

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