ios – 核心图形图像质量低

前端之家收集整理的这篇文章主要介绍了ios – 核心图形图像质量低前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是Core Graphics的新手,我试着画圆圈.它们可以是透明的(仅中风)并填充笔触颜色.所以方法看起来像这样:
  1. + (UIImage *)iconImageWithColor: (UIColor *)markColor strokeOnly:(BOOL)strokeOnly
  2. {
  3. CGRect rect = CGRectMake(0.0f,0.0f,20.0f,20.0f);
  4.  
  5. UIGraphicsBeginImageContext(rect.size);
  6. CGContextRef context = UIGraphicsGetCurrentContext();
  7.  
  8. CGPathRef clippingPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:7.5f].CGPath;
  9. CGContextAddPath(context,clippingPath);
  10. CGContextClip(context);
  11.  
  12. CGContextSetFillColorWithColor(context,strokeOnly == YES ? [[UIColor clearColor] CGColor] : [markColor CGColor]);
  13. CGContextFillRect(context,rect);
  14.  
  15. CGPathRef path = CGPathCreateWithRoundedRect(rect,10.f,NULL);
  16. [markColor setStroke];
  17. CGContextAddPath(context,path);
  18. CGContextDrawPath(context,kCGPathFillStroke);
  19.  
  20. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  21. UIGraphicsEndImageContext();
  22.  
  23. return image;
  24. }

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

解决方法

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

UIGraphicsBeginImageContextWithOptions(rect.size,NO,0.0f)

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

猜你在找的iOS相关文章