UIImageviewにある画像を任意の形にトリミングしたい
1876 次
2 に答える
2
クリッピングパスと出来上がりを設定します。
// 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が結果です。
于 2012-08-29T17:30:45.907 に答える
0
を使用できますCGImageMask
。
サンプルは、AppleのQuartzDemoのクラスQuartzMaskingViewにあります。
于 2012-09-05T11:47:42.513 に答える