2013-10-07 61 views
2

我正在为iPhone应用程序编写图像编辑器。我使用GPUImage library在画布上呈现精灵图像(在GPUImageView上)。我用下面的方法来获取画布的截图:如何获取包含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来渲染图像不石英的截图的问题。如何获取包含GPUImageView的视图截图?

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

回答

2

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

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

+0

剂量,这意味着我应该创建并添加新的UIImageView(s)到精灵(s)以呈现从-imageFromCurrentlyProcessedOutput'的UIImage,拍摄快照,然后从精灵中删除UIImageView(s)相同的运行循环? –