Blends with GPUImageView are not giving expected result

眉间皱痕 提交于 2019-12-24 08:12:26

问题


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];
}

回答1:


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).

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.

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.



来源:https://stackoverflow.com/questions/21369684/blends-with-gpuimageview-are-not-giving-expected-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!