核心graphics圆形图像模糊

我正在使用核心graphics绘制一个圆形图像与这个SO答案的修改实现

这是我的来源:

+ (UIImage*)circularImageWithRadius:(CGFloat)radius color:(UIColor*)color{ CGRect rect = CGRectMake(0.0f, 0.0f, radius*2, radius*2); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, color.CGColor); CGContextFillEllipseInRect(context, rect); UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } 

边缘是模糊的,我不知道为什么(我以为这是什么分辨率的设备是无关紧要,它将工作的开箱即用)。

我试着replaceCGContextFillEllipseInRect(context, rect);CGContextFillRect(context, rect); 这也是模糊的。 然后我尝试了CGContextFillRect(context, CGRectMake(0, 0, radius*4, radius*4) ,它完美的工作,清晰的图像和一切(尽pipe是一个方形,而不是一个圆),所以我改回CGContextDrawEllipseInRect(context, CGRectMake(0, 0, radius*4, radius*4)但是这是我的结果:

在这里输入图像说明

而使用矩形时,与使用半径* 2时的大小相同,但图像更清晰。

我怎样才能解决我的模糊问题,为什么CGContextFillEllipseInRect不填充预定义的图像矩形?

我感到愚蠢的发现后立即发布,但这个答案指出了道路。

我刚刚添加

 if(UIGraphicsBeginImageContextWithOptions != NULL) { UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0); } else { UIGraphicsBeginImageContext(rect.size); } 

而不仅仅是UIGraphicsBeginImageContext(rect.size); 进入我的原始来源,它清澈而锐利。