我正在尝试使用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看到背景视图。有关如何执行此操作的一些文档真的很棒!