我试图剪辑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
Run Code Online (Sandbox Code Playgroud)
这可以按照需要工作,但质量非常低,图像看起来很模糊,圆圈周围的边缘是锯齿状的.我想实现它们同样的影响:
image.layer.cornerRadius = self.thumbnailView.frame.size.width / 2;
image.clipsToBounds = YES;
Run Code Online (Sandbox Code Playgroud)
不确定为什么图像的质量如此之低.有人可以给我一些指示吗?
您可能希望将比例保持在0.f,因此它与设备比例(视网膜/非视网膜)匹配.
UIGraphicsBeginImageContextWithOptions(roundView.bounds.size, NO, 0.f);
Run Code Online (Sandbox Code Playgroud)
你也可以像这样绘制一个圆圈:
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.f);
CGRect interiorBox = CGRectInset(rect, 0.f, 0.f);
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:insideBox];
[bezierPath addClip];
[image drawInRect:rect];
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
323 次 |
| 最近记录: |