核心图形图像质量低

Shu*_*puS 6 core-graphics objective-c ios

我是Core Graphics的新手,我试着画圆圈.它们可以是透明的(仅中风)并填充笔触颜色.所以方法看起来像这样:

+ (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;
}
Run Code Online (Sandbox Code Playgroud)

结果很奇怪 - 看起来图像的分辨率非常低.是否有可能使结果图像在视网膜显示器上看起来很好?

奇怪的形象

Fab*_*ato 13

UIGraphicsBeginImageContext创建一个比例为1的上下文,所以非视网膜.你想要用的是

UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0f)

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