gpt4 book ai didi

ios - 将其剪辑成圆形后质量低的 UIImage

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:06:51 24 4
gpt4 key购买 nike

我正在尝试剪辑 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;

不知道为什么图像质量这么低。有人可以给我一些指示吗?

最佳答案

您可能希望将比例保持在 0.f,以便它匹配设备比例(视网膜/非视网膜)。

UIGraphicsBeginImageContextWithOptions(roundView.bounds.size, NO, 0.f);

你也可以像这样画一个圆:

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();

关于ios - 将其剪辑成圆形后质量低的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28582465/

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