ios - 屏幕截图中缺少 GPUImage 输出图像

标签 ios objective-c uiimage gpuimage

我正在 try catch 屏幕部分以在社交媒体上发布图像。

我正在使用以下代码来捕获屏幕。

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

    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
    return img;
}

以上代码非常适合捕获屏幕。

问题:

我的 UIView 包含带有过滤图像的 GPUImageView。当我尝试使用上面的代码捕获屏幕时,GPUImageView 的特定部分不包含过滤后的图像。

我将 GPUImageSwirlFilter 与静态图像(无相机)一起使用。我也试过了

UIImage *outImage = [swirlFilter imageFromCurrentFramebuffer]

但它没有给出图像。

注意: 以下是工作代码,它提供了完美的漩涡效果输出,但我想要在 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) 我对 GPUImage 的 imageFromCurrentFramebuffer 做错了吗?

2) 为什么 screen capture 代码 not 在输出图像中包含 GPUImageView 部分?

3) 如何在 UIImage 中获取 filtered 图像?

最佳答案

首先,-renderInContext: 不适用于 GPUImageView,因为 GPUImageView 使用 OpenGL ES 进行渲染。 -renderinContext: 不从 CAEAGLLayers 捕获,CAEAGLLayers 用于支持呈现 OpenGL ES 内容的 View 。

其次,您可能在后面的代码中得到了一个 nil 图像,因为您忘记在触发 -processImage 之前在过滤器上设置 -useNextFrameForImageCapture。否则,您的过滤器将不会在其后备帧缓冲区上停留足够长的时间来从中捕获图像。这是由于 a recent change in the way that framebuffers are handled in memory (尽管这种变化似乎没有得到很好的传达)。

关于ios - 屏幕截图中缺少 GPUImage 输出图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23323505/

相关文章:

iphone - Objective-C/iPhone 内存管理静态变量

objective-c - 如何在快速便捷的初始化程序中返回自定义对象?

iphone - UITableView 不会重新加载 contentSize

ios - 如何将 ScrollView 锁定到位?

iphone - 关闭模态视图 Controller

ios - 如何弱链接 iOS 应用程序委托(delegate)方法?

ios - 在一个屏幕上有一些 UITableViews 和一些 UICollectionViews

iphone - 无法通过在 ipad 中使用 OpenGL 获得裁剪图像的确切部分

ios - 在 Xcode 项目清理构建文件夹后,Images.xcassets 停止工作 - iOS

objective-c - 加快检查点像素颜色的速度