目前我正在使用以下代码对 UIImage 进行舍入:
//round the image
UIImageView *roundView = [[UIImageView alloc] initWithImage:smallImage];
UIGraphicsBeginImageContextWithOptions(roundView.bounds.size, NO, [UIScreen mainScreen].scale);
[[UIBezierPath bezierPathWithRoundedRect:roundView.bounds
cornerRadius:roundView.frame.size.width/2] addClip];
[smallImage drawInRect:roundView.bounds];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
smallImage = finalImage;
//end round image
self.thumbnailView.image=smallImage;
UIImageWriteToSavedPhotosAlbum(smallImage, self, nil, nil); //20kb
UIGraphicsEndImageContext();
然而,这会使圆圈的外部变白,因此当我按下图像(如果它被用作 UIButton)时,您可以看到它是一个方形图像。无论如何将 UIImage 剪辑成一个圆圈但使其外部透明?任何指针将不胜感激。
最佳答案
你可以设置 UIImageView
的圆角半径,让它像这样变圆:-
[yourImageView.layer setCornerRadius:CGRectGetWidth(yourImageView.frame)/2];
您可以增加它以使其变小。
关于ios - 将 UIImage 圆角化但使圆的外部透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29115535/