gpt4 book ai didi

ios - 裁剪一个70*70px的正方形为正方形

转载 作者:行者123 更新时间:2023-11-28 21:50:23 25 4
gpt4 key购买 nike

在我使用下面的代码制作我的 UIImage 之前:

image.layer.cornerRadius = button.frame.size.width / 2;
image.clipsToBounds = YES;

图像大小为 70*70px,我想在 CGImageContext 中执行相同操作并保存结果,而不是像上面那样设置圆角半径,因为这会显着降低 UI 速度。在 CGImageContext 中有没有办法做到这一点?谢谢

最佳答案

您可以设置一个圆角蒙版而不是圆角,这会降低性能。

swift :

let roundMaskLayer = CAShapeLayer()
roundMaskLayer.path = UIBezierPath(roundedRect: self.YOURIMAGEVIEW.bounds, byRoundingCorners: UIRectCorner.AllCorners, cornerRadii: CGSize(width: self.YOURIMAGEVIEW.frame.size.width/2,height: self.YOURIMAGEVIEW.frame.size.height/2)).CGPath
self.YOURIMAGEVIEW.layer.mask = roundMaskLayer
self.YOURIMAGEVIEW.layer.masksToBounds = true

objective-C :

CAShapeLayer *roundMaskLayer = [[CAShapeLayer alloc] init];
roundMaskLayer.path = (__bridge CGPathRef)([UIBezierPath bezierPathWithRoundedRect:self.YOURIMAGEVIEW.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(self.YOURIMAGEVIEW.bounds.size.width/2, self.YOURIMAGEVIEW.bounds.size.height/2)]);
self.YOURIMAGEVIEW.layer.mask = roundMaskLayer;
self.YOURIMAGEVIEW.layer.masksToBounds = true;

关于ios - 裁剪一个70*70px的正方形为正方形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28579789/

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