我想将图像转换为黑色和白色。我尝试了以下代码,但imageFromCurrentFramebufferWithOrientation始终返回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];

}

最佳答案

对于the recent changes in the way that GPUImage handles framebuffers,您需要添加以下行

[conversionFilter useNextFrameForImageCapture];

就在之前
[gpuImage processImage];

在上面的代码中。您需要让框架知道在处理完图像并从中捕获结果之前不要回收最后一个过滤器的帧缓冲区。

关于ios - imageFromCurrentFramebufferWithOrientation返回nil GPUImagePicture?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22993251/

10-09 14:13