简体   繁体   English

屏幕捕获中缺少GPUImage输出图像

[英]GPUImage output image is missing in screen capture

I am trying to capture screen portion to post image on social media. 我正在尝试捕获屏幕部分以在社交媒体上发布图像。

I am using following code to capture screen. 我正在使用以下代码来捕获屏幕。

- (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
    return img;
}

Above code is perfect for capturing screen. 以上代码非常适合捕获屏幕。

Problem : 问题:

My UIView contains GPUImageView with the filtered image. 我的UIView包含带有过滤图像的GPUImageView When I tries to capture screen using above code, that particular portion of GPUImageView does not contains the filtered image. 当我尝试使用上面的代码捕获屏幕时,GPUImageView的特定部分不包含过滤后的图像。

I am using GPUImageSwirlFilter with the static image (no camera). 我正在使用GPUImageSwirlFilter与静态图像(没有相机)。 I have also tried 我也试过了

UIImage *outImage = [swirlFilter imageFromCurrentFramebuffer]

but its not giving image. 但它没有给出形象。

Note : Following is working code, which gives perfect output of swirl effect, but I want same image in UIImage object. 注意:以下是工作代码,它提供了旋转效果的完美输出,但我想在UIImage对象中使用相同的图像。

 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

        GPUImageSwirlFilter *swirlFilter = [GPUImageSwirlFilter alloc] init];
        swirlLevel = 4;
        [swirlFilter setAngle:(float)swirlLevel/10];
        UIImage *inputImage = [UIImage imageNamed:gi.wordImage];
        GPUImagePicture  *swirlSourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage];
        inputImage = nil;
        [swirlSourcePicture addTarget:swirlFilter];
        dispatch_async(dispatch_get_main_queue(), ^{
            [swirlFilter addTarget:imgSwirl];
            [swirlSourcePicture processImage];
            // This works perfect and I have filtered image in my imgSwirl. But I want
            // filtered image in UIImage to use at different place like posting 
            // on social media
            sharingImage = [swirlFilter imageFromCurrentFramebuffer];  // This also 
            // returns nothing.
        });
    });

1) Am I doing something wrong with GPUImage's imageFromCurrentFramebuffer ? 1)我是否在使用GPUImage's imageFromCurrentFramebuffer什么?

2) And why does screen capture code is not including GPUImageView portion in output image ? 2)为什么screen capture代码not包括输出图像中的GPUImageView部分?

3) How do I get filtered image in UIImage ? 3)如何在UIImage获得filtered图像?

First, -renderInContext: won't work with a GPUImageView, because a GPUImageView renders using OpenGL ES. 首先, -renderInContext:不能与GPUImageView一起使用,因为GPUImageView使用OpenGL ES渲染。 -renderinContext: does not capture from CAEAGLLayers, which are used to back views presenting OpenGL ES content. -renderinContext:不从CAEAGLLayers捕获,CAEAGLLayers用于支持呈现OpenGL ES内容的视图。

Second, you're probably getting a nil image in the latter code because you've forgotten to set -useNextFrameForImageCapture on your filter before triggering -processImage . 其次,你可能在后面的代码中得到一个nil图像,因为你忘了在触发-processImage之前在你的过滤器上设置-useNextFrameForImageCapture Without that, your filter won't hang on to its backing framebuffer long enough to capture an image from it. 如果没有它,您的过滤器将不会长时间停留在其后备帧缓冲区上以从中捕获图像。 This is due to a recent change in the way that framebuffers are handled in memory (although this change did not seem to get communicated very well). 这是由于最近在内存中处理帧缓冲区的方式发生了变化 (虽然这种变化似乎没有得到很好的沟通)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM