Ios 核心图形图像质量低

Ios 核心图形图像质量低,ios,objective-c,core-graphics,Ios,Objective C,Core Graphics,我是核心图形的新手,我试着画圆圈。它们可以是透明的(只有笔划)并用笔划颜色填充。因此,该方法如下所示: + (UIImage *)iconImageWithColor: (UIColor *)markColor strokeOnly:(BOOL)strokeOnly { CGRect rect = CGRectMake(0.0f, 0.0f, 20.0f, 20.0f); UIGraphicsBeginImageContext(rect.size); CGContext

我是核心图形的新手,我试着画圆圈。它们可以是透明的(只有笔划)并用笔划颜色填充。因此,该方法如下所示:

+ (UIImage *)iconImageWithColor: (UIColor *)markColor strokeOnly:(BOOL)strokeOnly
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 20.0f, 20.0f);

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGPathRef clippingPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:7.5f].CGPath;
    CGContextAddPath(context, clippingPath);
    CGContextClip(context);

    CGContextSetFillColorWithColor(context, strokeOnly == YES ? [[UIColor clearColor] CGColor] : [markColor CGColor]);
    CGContextFillRect(context, rect);

    CGPathRef path = CGPathCreateWithRoundedRect(rect, 10.f, 10.f, NULL);
    [markColor setStroke];
    CGContextAddPath(context, path);
    CGContextDrawPath(context, kCGPathFillStroke);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}
结果很奇怪——看起来图像的分辨率很低。是否有可能使结果图像在视网膜显示器上看起来很好


UIGraphicsBeginImageContext
创建一个刻度为1的上下文,因此它不是视网膜。 你想用的是


UIGraphicsBeginImageContextWithOptions(rect.size,NO,0.0f)


比例0表示它将使用设备屏幕比例

使用
UIGraphicsBeginImageContextWithOptions(rect.size,是,0.0)


最后一个参数表示结果像素密度(比例)。当您通过0时,它会自动从设备本机屏幕比例中拾取它。

在绘制rect之前添加此行:CGContextSetLineWidth(上下文,1.0);您可以根据需要将1.0更新为。它的画线宽度。难以置信,你是我的掌上明珠