GPUImage imageFromCurrentFramebuffer returning nil sometimes for GPUImageLookupFilter and it's subclasses

无人久伴 提交于 2019-12-07 06:59:38

问题


I have been using GPUImage for my project and I am getting into this problem where imageFromCurrentFramebuffer returns nil for some of the GPUImageLookupFilter's.

I subclassed GPUImageFilterGroup like in the GPUImageAmatorkaFilter my code is as follows:

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

I have several of the objects of this class added into an array and I use:

- (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");
      }
  }

The returned image from imageFromCurrentFramebuffer is sometimes nil and I do not understand it's cause. I would be thankful for any help. Sometimes the image is nil even for the filters, GPUImageAmatorkaFilter, GPUImageSoftEleganceFilter and `GPUImageMissEtikateFilter so I know it is not a problem with my subclass.

来源:https://stackoverflow.com/questions/23803436/gpuimage-imagefromcurrentframebuffer-returning-nil-sometimes-for-gpuimagelookupf

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