我想将 UIImageview 上的图像裁剪成任何形状
最佳答案
您设置了剪切路径,瞧:
// Load image thumbnail
NSString *imageName = [self.picArray objectAtIndex:indexPath.row];
UIImage *image = [UIImage imageNamed:imageName];
CGSize imageSize = image.size;
CGRect imageRect = CGRectMake(0, 0, imageSize.width, imageSize.height);
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
// Create the clipping path and add it
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:imageRect cornerRadius:5.0f];
[path addClip];
[image drawInRect:imageRect];
UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
此代码加载图像并通过圆角矩形创建路径,结果是最终图像被裁剪,即圆角。 RoundedImage 就是结果。
关于objective-c - 如何在iOS中将图像裁剪成多边形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12280561/