bar*_*dog 3 core-graphics objective-c ios
我正在使用核心图形绘制圆形图像,并修改了此SO答案的实现
这是我的来源:
+ (UIImage*)circularImageWithRadius:(CGFloat)radius color:(UIColor*)color{
CGRect rect = CGRectMake(0.0f, 0.0f, radius*2, radius*2);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillEllipseInRect(context, rect);
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Run Code Online (Sandbox Code Playgroud)
边缘模糊,我不知道为什么(我认为设备的分辨率无关紧要,它可以直接使用).
我尝试替换CGContextFillEllipseInRect(context, rect);,CGContextFillRect(context, rect);这也很模糊.然后我尝试了CGContextFillRect(context, CGRectMake(0, 0, radius*4, radius*4)它完美,清晰的图像和一切(虽然是一个正方形,而不是一个圆圈).所以我改回去了,CGContextDrawEllipseInRect(context, CGRectMake(0, 0, radius*4, radius*4)但这是我的结果:

而对于矩形,它与使用半径*2时的大小相同,但图像更清晰.
如何修复模糊问题以及为什么不CGContextFillEllipseInRect填充预定义的图像rect?
在我发布后立即发现这个问题我感到愚蠢,但这个答案指明了方向.
我刚才补充道
if(UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);
} else {
UIGraphicsBeginImageContext(rect.size);
}
Run Code Online (Sandbox Code Playgroud)
而不仅仅是UIGraphicsBeginImageContext(rect.size);我的原始来源,它是晶莹剔透的.
| 归档时间: |
|
| 查看次数: |
958 次 |
| 最近记录: |