如何获取包含GPUImageView的视图的屏幕截图? [英] How to get a screenshot of a view containing GPUImageView?
问题描述
我正在为iPhone App编写图像编辑器.我使用 GPUImage库在画布上呈现Sprite的图像(在GPUImageView上).我使用以下方法获取画布的屏幕截图:
I'm writing an image editor for an iPhone App. I use GPUImage library to present an image (on GPUImageView) of the sprite on the canvas. And I use the following method to get the screenshot of the 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
使用此方法获取关键窗口的整个屏幕截图后,画布的字段为空(没有任何精灵的图像).
After I used this method to get the whole screenshot of key window, the field of the canvas was empty (no image of any sprite).
UIView *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIImage *snapshotIamge = [keyWindow snapshot];
// Present the image on the view...
我认为获取包含GPUImageView的视图的屏幕快照存在问题,该视图使用 OpenGLES 渲染非 Quartz 的图像.如何获取包含GPUImageView的视图的屏幕截图?
I think there is a problem to get a screenshot of a view containing GPUImageView(s), which use OpenGLES to render images not Quartz. How to get a screenshot of a view containing GPUImageView?
在截屏时是否可以获取具有特定CGRect的裁剪图像(如Mac上的cmd + shift + 4
)?
And is it possible to get a cropped image with a specific CGRect when taking a screenshot (like cmd + shift + 4
on Mac)?
推荐答案
如您所见,-renderInContext:
不适用于OpenGL ES内容.您需要的是从GPUImage本身提取处理后的图像.
As you found, -renderInContext:
doesn't work with OpenGL ES content. What you're going to need is to extract the processed image from GPUImage itself.
为此,请在直接送入GPUImageView的过滤器上调用-imageFromCurrentlyProcessedOutput
.这将为您提供一个UIImage,其中包含最终的经过过滤的图像.然后,您可以直接使用它,也可以将其与周围视图中的其余内容合成.
To do this, call -imageFromCurrentlyProcessedOutput
on the filter that feeds directly into your GPUImageView. This will give you a UIImage with the final filtered image within it. You can then either use this directly, or you can composite it with the remaining content from your surrounding views.
这篇关于如何获取包含GPUImageView的视图的屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!