gpt4 book ai didi

ios - Core Graphics 圆形图像模糊

转载 作者:可可西里 更新时间:2023-11-01 06:23:14 25 4
gpt4 key购买 nike

我正在使用核心图形绘制圆形图像,并修改了此 SO answer 的实现

这是我的来源:

+ (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); 替换为 CGContextFillRect(context, rect); ,这也很模糊。然后我尝试了 CGContextFillRect(context, CGRectMake(0, 0, radius*4, radius*4) 并且它完美地工作,清晰的图像和一切(尽管是正方形,而不是圆形)。所以我改回 CGContextDrawEllipseInRect(context, CGRectMake(0, 0, radius*4, radius*4) 但这是我的结果:

enter image description here

而对于矩形,它的大小与使用半径*2 时的大小相同,但图像更清晰。

如何解决我的模糊问题以及为什么 CGContextFillEllipseInRect 没有填充预定义图像矩形?

最佳答案

我发帖后立即发现了这个,但我感到很愚蠢this answer指明了方向。

我刚刚添加

if(UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);
} else {
UIGraphicsBeginImageContext(rect.size);
}

而不仅仅是 UIGraphicsBeginImageContext(rect.size); 进入我的原始来源,它非常清晰锐利。

关于ios - Core Graphics 圆形图像模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21108504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com