如何在CGContext中使用另一个图像剪辑图像?

时间:2012-08-24 04:55:26

标签: iphone ios cgcontext masking clipping

我想用两张图片得到以下结果。

请帮帮我。

2 个答案:

答案 0 :(得分:3)

要在图像视图上组合两个图像,请尝试以下

UIImage *bottomImage = [UIImage imageNamed:@"bottom.png"]; //background image
UIImage *image       = [UIImage imageNamed:@"top.png"]; //foreground image
CGSize newSize = CGSizeMake(width, height);
UIGraphicsBeginImageContext( newSize );
// Use existing opacity as is
[bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Apply supplied opacity if applicable
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

newImage添加到UIImageView

答案 1 :(得分:3)

在@ Sumanth组合两张图片的代码之后,您需要屏蔽最终图像,例如how-to-mask-an-image链接