uiview - 如何获取包含GPUImageView的 View 的屏幕截图?

标签 uiview uiimage screenshot gpuimage

我正在为 iPhone 应用程序编写图像编辑器。我用GPUImage library在 Canvas 上呈现 Sprite 的图像(在 GPUImageView 上)。我使用以下方法来获取 Canvas 的屏幕截图:

@implementation UIView (SnapshotImage)
// Return a snapshot image of this view
- (UIImage*)snapshot{

    UIGraphicsBeginImageContextWithOptions(self.bounds.size,YES,0.0f);
    CGContextRef context = UIGraphicsGetCurrentContext();

    // In iOS 7, you can use the following instead of `-renderInContext:`. It should be faster.
    // [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
    [self.layer renderInContext:context];

    UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return capturedImage;
}
@end

当我使用此方法获取关键窗口的整个屏幕截图后, Canvas 的字段为空(没有任何 Sprite 的图像)。

UIView *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIImage *snapshotIamge = [keyWindow snapshot];
// Present the image on the view...

我认为获取包含 GPUImageView 的 View 的屏幕截图存在问题,该 View 使用 OpenGLES 渲染图像而不是 Quartz。如何获取包含GPUImageView的 View 的屏幕截图?

截屏时是否可以使用特定的 CGRect 获取裁剪后的图像(如 Mac 上的 cmd + shift + 4)?

最佳答案

正如您所发现的,-renderInContext: 不适用于 OpenGL ES 内容。您需要的是从 GPUImage 本身提取处理后的图像。

为此,请在直接输入 GPUImageView 的过滤器上调用 -imageFromCurrentlyProcessedOutput。这将为您提供一个 UIImage,其中包含最终的过滤图像。然后,您可以直接使用它,也可以将其与周围 View 中的剩余内容合成。

关于uiview - 如何获取包含GPUImageView的 View 的屏幕截图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19218126/

相关文章:

iphone - 显示 UIImageview 的顶部

html - 如何拍摄客户区的快照/打印屏幕并将其保存为数据库中的图像?

android - 在android中以编程方式截取屏幕截图

ios - 代码 8 : Interface builder shows different color that set

ios - AutoLayout UIScrollView 内容在旋转时不调整大小(包括示例项目)

iphone - 单击 objective-c 中的按钮更改图像

javascript - html2canvas当body高度超过30000像素时返回无效图片

ios - 如何将我的 View 之一与 UIView 类连接?

ios - 使用多个 UIViews 而不是多个 UIViewControllers

ios - 可调整大小的 UIImage,其中外部拉伸(stretch)和内部保持不变