Pergunta

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];

}

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top