I am just testing the following code to round corners on 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;
}
I looks fine unless you look closely to generated image. Corners are not smooth. How can I make corners to be smoother/softer ?
EDIT:
Processed image with rounded corners in quartz:
Like you can see corner is not smooth.
This is version with UIImageView's cornerRadius that is much more smoother.
Where is the catch ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…