繁体   English   中英

核心图形图像质量低

[英]Core graphics images low quality

我是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;
}

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

奇怪的形象

UIGraphicsBeginImageContext创建一个比例为1的上下文,因此非视网膜。 你想要用的是

UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0f)

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

使用UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0);

最后一个参数表示结果像素密度(比例)。 当您传递0时,它会从设备本机屏幕比例自动选择它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM