imageFromCurrentFramebufferWithOrientation returns nil GPUImagePicture?

StackOverflow https://stackoverflow.com/questions/22993251

  •  01-07-2023
  •  | 
  •  

سؤال

I want to convert image to black and white. i have tried the following code but imageFromCurrentFramebufferWithOrientation always returns nil.

-(UIImage *)convertImageToBlackAndWhite:(UIImage *)image{
GPUImagePicture *gpuImage = [[GPUImagePicture alloc] initWithImage:image];
GPUImageSobelEdgeDetectionFilter *edgeFilter = [[GPUImageSobelEdgeDetectionFilter alloc] init];

GPUImageColorMatrixFilter *conversionFilter = [[GPUImageColorMatrixFilter alloc] init];
conversionFilter.colorMatrix = (GPUMatrix4x4){
    {0.0, 0.0, 0.0, 1.0},
    {0.0, 0.0, 0.0, 1.0},
    {0.0, 0.0, 0.0, 1.0},
    {1.0,0.0,0.0,0.0},
};

[gpuImage addTarget:edgeFilter];
[edgeFilter addTarget:conversionFilter];
[gpuImage processImage];
NSLog(@"%@",[conversionFilter imageFromCurrentFramebufferWithOrientation:0]);
return [conversionFilter imageFromCurrentFramebufferWithOrientation:0];

}

هل كانت مفيدة؟

المحلول

Per the recent changes in the way that GPUImage handles framebuffers, you need to add the line

[conversionFilter useNextFrameForImageCapture];

right before

[gpuImage processImage];

in the above code. You need to let the framework know to not recycle the framebuffer for your last filter until you've processed your image and captured the result from it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top