与GPUImageView的混合未给出预期的结果 [英] Blends with GPUImageView are not giving expected result

查看:79
本文介绍了与GPUImageView的混合未给出预期的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将混合与GPUImageView一起使用时,它们似乎不起作用.例如,将结果抓取到图像中并将其放入imageView的test1可以正常工作……其中将GPUImageView设置为目标的test2似乎不起作用. test1给了我期望的图像...测试图像给了我test2给了我黑屏.

When I use blends with a GPUImageView they don't seem to work. For example test1 which grabs the result into an image and puts that into an imageView works... where test2 which set the GPUImageView as a target... doesn't seem to work. test1 gives me the expected image... with my test images test2 gives me a black screen.

+ (void)test1:(UIImage*)image imageView:(UIImageView*)imageView {
    GPUImagePicture *pictureBase = [[GPUImagePicture alloc] initWithImage:image];
    GPUImagePicture *pictureOverlay = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"overlay.png"]];

    GPUImageMultiplyBlendFilter *filter = [[GPUImageMultiplyBlendFilter alloc] init];

    [pictureBase addTarget:filter];
    [pictureOverlay addTarget:filter];

    [pictureBase processImage];
    [pictureOverlay processImage];

    imageView.image = [filter imageFromCurrentlyProcessedOutputWithOrientation:UIImageOrientationUp];
}

+ (void)test2:(UIImage*)image gpuImageView:(GPUImageView*)gpuImageView {
    GPUImagePicture *pictureBase = [[GPUImagePicture alloc] initWithImage:image];
    GPUImagePicture *pictureOverlay = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"overlay.png"]];

    GPUImageMultiplyBlendFilter *filter = [[GPUImageMultiplyBlendFilter alloc] init];

    [pictureBase addTarget:filter];
    [pictureOverlay addTarget:filter];

    [filter addTarget:gpuImageView];

    [pictureBase processImage];
    [pictureOverlay processImage];
}

推荐答案

我相信这里发生的是,在该方法的末尾(如果这是启用了ARC的项目)正在重新分配您的GPUImagePicture实例.发生这种情况时,它将地毯从其余过滤链的下方拉出,并在视图中导致黑色图像(您可能会短暂看到正确的图像出现,然后闪烁为黑色).

I believe what's happening here is that your GPUImagePicture instance is being deallocated at the end of that method (if this is an ARC-enabled project). When that happens, it pulls the rug out from underneath the rest of your filter chain, and leads to a black image in your view (you might briefly see the correct image appear, then flicker to black).

对于提取UIImage的情况不会发生这种情况,因为UIImage块的提取直到处理完成为止,之后过滤链将发生什么无关紧要.

This doesn't happen for the case where you extract the UIImage, because the extraction of the UIImage blocks until the processing is done, after which it doesn't matter what happens to your filter chain.

为防止这种情况,请使您的GPUImagePicture成为您所包含类的实例变量,以使其挂起的时间长于方法结尾的时间.

To prevent this, make your GPUImagePicture an instance variable on your encompassing class, so that it hangs around longer than the end of your method.

这篇关于与GPUImageView的混合未给出预期的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆