我一直在使用GPUImage
用于我的项目,我遇到了这个问题,其中imageFromCurrentFramebuffer
对GPUImageLookupFilter's
的某些内容返回nil。
我将GPUImageFilterGroup
中的GPUImageAmatorkaFilter
子类化为-(MTLookupFilter *) initWithLookupImageName:(NSString *) lookupImageName {
self = [super init];
if (self) {
UIImage *image = [UIImage imageNamed:lookupImageName];
self.lookupImageSource = [[GPUImagePicture alloc] initWithImage:image];
GPUImageLookupFilter *lookupFilter = [[GPUImageLookupFilter alloc] init];
[self addFilter:lookupFilter];
[self.lookupImageSource addTarget:lookupFilter atTextureLocation:1];
[self.lookupImageSource processImage];
self.initialFilters = [NSArray arrayWithObjects:lookupFilter, nil];
self.terminalFilter = lookupFilter;
}
return self;
}
我的代码如下:
- (IBAction)filterAction:(id)sender {
NSInteger index = arc4random()%self.filtersArray.count;
id filter = self.filtersArray[index];
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:self.fullImage];
UIImage *filteredimage = nil;
[stillImageSource addTarget:filter];
[stillImageSource processImage];
[filter useNextFrameForImageCapture];
filteredimage = [filter imageFromCurrentFramebuffer];
if (filteredimage) {
self.imageView.image = filteredimage;
} else {
NSLog(@"Filtered image is nil");
}
}
我将这个类的几个对象添加到数组中并使用:
imageFromCurrentFramebuffer
来自GPUImageAmatorkaFilter
的返回图片有时为零,我不明白它的原因。我会感谢任何帮助。有时即使对于过滤器GPUImageSoftEleganceFilter
,{{1}}和`GPUImageMissEtikateFilter,图像也是零,所以我知道它对我的子类来说不是问题。