使用Core Graphics绘图在Retina显示屏上看起来很粗糙 [英] Drawing with Core Graphics looks chunky on Retina display

查看:133
本文介绍了使用Core Graphics绘图在Retina显示屏上看起来很粗糙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView,它从drawRect:rect中画一个圆圈。在Retina显示屏上阅读Apple dev信息后,似乎使用Core Graphics意味着图纸会自动利用更高的分辨率。然而,与徽章图标中的类似圆圈相比,这个简单的圆圈看起来相当粗糙。显然,我将它与具有光泽和阴影的东西进行比较,但我认为很明显我的绘制也不是很好。我尝试截取苹果图标徽章和我的圈子的屏幕截图,他们在我的Mac上看起来一样 - 不过在看电话的时候差别很明显。这里有什么简单的东西吗?

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?

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

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];

感谢您的帮助,
Rob

Thanks for any help, Rob

推荐答案

哎呀,首先需要抗锯齿:

Oops, it needed antialiasing first:

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

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

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.

这篇关于使用Core Graphics绘图在Retina显示屏上看起来很粗糙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆