我编写了一种方法来过滤具有亮度因子和对比度因子的图像,如下所示:
- (UIImage*)image:(UIImage*)image withBrightness:(float)brightness contrast:(float)contrast{
GPUImagePicture *imagePicture = [[GPUImagePicture alloc] initWithImage:image];
GPUImageBrightnessFilter *brightnessFilter = [[GPUImageBrightnessFilter alloc] init];
GPUImageContrastFilter *contrastFilter = [[GPUImageContrastFilter alloc] init];
[imagePicture addTarget:brightnessFilter];
[brightnessFilter addTarget:contrastFilter];
brightnessFilter.brightness = brightness; // set brightness
contrastFilter.contrast = contrast; // set contrast
[imagePicture processImage];
UIImage *filteredImage = [contrastFilter imageFromCurrentlyProcessedOutput];
return filteredImage;
}
调用此实现会引发错误:<Error>: CGContextDrawImage: invalid context 0x0
.
如何使用 GPUImage 正确实现亮度和对比度调整?