我是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,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表示它将使用设备屏幕比例
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。