【发布时间】:2015-02-18 19:45:09
【问题描述】:
我正在尝试剪辑 UIImage 以使其成为圆形,我从 140*140px 图像开始,然后运行此代码:
//round the image
UIImageView *roundView = [[UIImageView alloc] initWithImage:smallImage];
UIGraphicsBeginImageContextWithOptions(roundView.bounds.size, NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:roundView.bounds
cornerRadius:roundView.frame.size.width/2] addClip];
[smallImage drawInRect:roundView.bounds];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
smallImage = finalImage;
//end round image
这可以正常工作,但质量非常低,图像看起来很模糊,圆圈周围的边缘呈锯齿状。我想达到与以下相同的效果:
image.layer.cornerRadius = self.thumbnailView.frame.size.width / 2;
image.clipsToBounds = YES;
不知道为什么图片质量这么低。有人可以给我一些指点吗?
【问题讨论】:
-
剪裁你的 UIImage 使其成为圆形是可取的..??您可以更改圆形图像视图,而不是在 imageView 中添加您的图像..
-
我以前也这样做过,但我在 tableview 中有很多 UIImage,所以四舍五入的图像视图会大大降低性能。
-
@Kex 对我来说听起来你是在
cellForRowAtIndexPath方法中执行此操作。这样做是错误的。只有少数细胞被创建然后出队。您需要为每个创建的单元执行一次此操作。那么它就已经有了圆角,以备将来重复使用。