我正在尝试使用 GPUImage 过滤视图,因为它在一种 iOS 7 样式覆盖中更新。为此,我在 NSTimer 上运行以下代码,但是我的 NSLog 显示[self.backgroundUIImage imageFromCurrentlyProcessedOutput]
正在返回(null)我知道视图 self.background 工作正常,因为它也被添加到视图中(self.finalImageView 也已经已添加到视图中)。我不确定我是否以正确的方式进行此操作,因为在 GPUImage github 页面上没有关于如何执行此操作的真实文档。有谁知道是否可以以这种方式使用 GPUImage?
if (!self.backgroundUIImage) {
self.backgroundUIImage = [[GPUImageUIElement alloc] initWithView:self.background];
GPUImageFastBlurFilter *fastBlur = [[GPUImageFastBlurFilter alloc] init];
fastBlur.blurSize = 0.5;
[self.backgroundUIImage addTarget:fastBlur];
[self.backgroundUIImage update];
}
[self.backgroundUIImage update];
NSLog(@"image : %@",[self.backgroundUIImage imageFromCurrentlyProcessedOutput]);
self.finalImageView.image = [self.backgroundUIImage imageFromCurrentlyProcessedOutput];
[self bringSubviewToFront:self.finalImageView];
编辑 1
我现在查看了 FilterShowcase 示例代码,因此我现在尝试像这样实现实时模糊:
NSLog(@"regenerating view");
if (!self.backgroundUIImage) {
GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 1.0;
self.backgroundUIImage = [[GPUImageUIElement alloc] initWithView:self.background];
NSLog(@"self.backgroundUIImage : %@",self.backgroundUIImage);
self.filter = [[GPUImageFastBlurFilter alloc] init];
self.filter.blurSize = 10;
[self.filter addTarget:blendFilter];
[self.backgroundUIImage addTarget:blendFilter];
[blendFilter addTarget:self.finalImageView];
__unsafe_unretained GPUImageUIElement *weakUIElementInput = self.backgroundUIImage;
[self.filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
[weakUIElementInput update];
}];
}
__unsafe_unretained GPUImageUIElement *weakUIElementInput = self.backgroundUIImage;
[self.filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
[weakUIElementInput update];
}];
[self bringSubviewToFront:self.finalImageView];
@properties 的设置如下:
@property (nonatomic, strong) GPUImageView *finalImageView;
@property (nonatomic, strong) SMBouncingBubblesBackground *background;
@property (nonatomic, strong) GPUImageUIElement *backgroundUIImage;
@property (nonatomic, strong) GPUImageFastBlurFilter *filter;
看起来它没有生成图像,因为我可以通过 self.finalImageView 看到背景视图。一些关于如何做到这一点的文档真的很棒!