【发布时间】:2014-12-17 12:37:18
【问题描述】:
我是 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;
}
结果很奇怪——看起来图像的分辨率很低。是否可以使结果图像在视网膜显示器上看起来不错?
【问题讨论】:
-
在绘制矩形之前添加这条线:CGContextSetLineWidth(context, 1.0);您可以根据您的要求将 1.0 更新为。它的画线宽度。
标签: ios objective-c core-graphics