【问题标题】:Get UIImage from UIImageView with masked subviews从带有掩码子视图的 UIImageView 获取 UIImage
【发布时间】:2013-12-03 11:11:50
【问题描述】:

通过人脸检测,我想模糊一个人的眼睛和嘴巴。所以我有一个包含 3 个子视图(每只眼睛和嘴巴 2 个)的 imageView。这些子视图中的每一个都被一个 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 兼容的库

【问题讨论】:

    标签: objective-c uiimageview uiimage mask


    【解决方案1】:

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

    • snapshotViewAfterScreenUpdates:

    • resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets: 用于可调整大小的图像

    • drawViewHierarchyInRect:afterScreenUpdates:

    【讨论】:

    • 感谢您的回答,但我的应用程序应该是为 iOS6 制作的 :(
    猜你喜欢
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 2016-02-19
    • 2013-10-13
    相关资源
    最近更新 更多