我正在使用核心图形绘制圆形图像,并对其进行修改后的实现所以答案 https://stackoverflow.com/a/18664917/1369331
这是我的来源:
+ (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;
}
边缘很模糊,我不确定为什么(我认为设备的分辨率并不重要,它开箱即用)。
我尝试更换CGContextFillEllipseInRect(context, rect);
with CGContextFillRect(context, rect);
那也很模糊。然后我尝试了CGContextFillRect(context, CGRectMake(0, 0, radius*4, radius*4)
它工作完美,图像清晰,一切都很好(尽管是正方形,而不是圆形)。所以我又改回CGContextDrawEllipseInRect(context, CGRectMake(0, 0, radius*4, radius*4)
但这是我的结果:
而对于矩形,它的大小与使用半径*2时相同,但图像更清晰。
我怎样才能解决我的模糊问题以及为什么CGContextFillEllipseInRect
不填充预定义的图像矩形?