【问题标题】:How to get a screenshot of a view containing GPUImageView?如何获取包含 GPUImageView 的视图的屏幕截图?
【发布时间】:2013-10-08 06:46:17
【问题描述】:

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

@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

我用这种方法得到关键窗口的整个截图后,画布的字段是空的(没有任何精灵的图像)。

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

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

在截屏时是否可以获得带有特定 CGRect 的裁剪图像(如 Mac 上的cmd + shift + 4)?

【问题讨论】:

    标签: uiview uiimage screenshot gpuimage


    【解决方案1】:

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

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

    【讨论】:

    • 这意味着我应该创建新的 UIImageView(s) 并将其添加到 sprite(s) 以呈现来自 -imageFromCurrentlyProcessedOutput 的 UIImage,拍摄快照,然后从 sprite 中删除 UIImageView(s) (s) 在同一个运行循环中?
    猜你喜欢
    • 2020-08-12
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多