【发布时间】:2013-08-08 19:48:15
【问题描述】:
我只是在 UIImage 上测试以下代码来圆角:
- (UIImage *)makeRoundedImage:(UIImage *)image radius:(float)radius;
{
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = CGRectMake(0, 0, image.size.width, image.size.height);
imageLayer.contents = (id) image.CGImage;
imageLayer.masksToBounds = YES;
imageLayer.cornerRadius = radius;
UIGraphicsBeginImageContext(image.size);
[imageLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return roundedImage;
}
除非您仔细查看生成的图像,否则我看起来很好。边角不光滑。我怎样才能使角落更平滑/更柔软?
编辑:
石英圆角处理后的图像:
你可以看到角落不光滑。
这是 UIImageView 的cornerRadius 更平滑的版本。
问题在哪里?
【问题讨论】:
-
您能否发布您要裁剪的图像以及结果如何?
-
我不想将圆角应用到 UIImageView 因为我想将此图像保存到文件系统。
-
我刚刚更新了问题...
-
将 UIGraphicsBeginImageContext 更改为 UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]);
-
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);会有同样的效果
标签: iphone ios uiimage rounded-corners smooth