从带有掩码子视图的UIImageView获取UIImage

时间:2013-12-03 11:11:51

标签: objective-c uiimageview uiimage mask

通过人脸检测,我想模糊一个人的眼睛和嘴巴。所以我有一个包含3个子视图的imageView(每个眼睛和嘴巴2个)。这些子视图中的每一个都被PNG形状(背景清晰)遮盖,以避免显示矩形。 屏幕上的我的imageView保持不变:http://screencast.com/t/ak4SkNXM0I

我想获取存储在另一个地方的图像,所以我试过这个:

CGSize size = [imageView bounds].size;
UIGraphicsBeginImageContext(size);
[[imageView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是finalImage是这样的图像:

http://screencast.com/t/eDlvGqqY

我的子视图(眼睛和嘴巴)没有像上面那样被屏蔽。

有什么想法吗?

感谢。

编辑:

我必须使用与ios6兼容的库

1 个答案:

答案 0 :(得分:0)

您可以查看添加到iOS7的新API。请尝试以下方法之一:

  • snapshotViewAfterScreenUpdates:

  • resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:可调整大小的图片

  • drawViewHierarchyInRect:afterScreenUpdates: