比如对图片进行实时亮度调整
用GPUImage处理如下
self.brightnessFilter = [[GPUImageBrightnessFilter alloc] init];
self.imagePicture = [[GPUImagePicture alloc] initWithImage:_originImage];
[self.imagePicture addTarget:_brightnessFilter];
[self.imagePicture processImage];
- (IBAction)valueChangeAction:(UISlider *)brightnessSlider{
[self.brightnessFilter setBrightness:[brightnessSlider value]];
self.editImageView.image = [self.brightnessFilter imageByFilteringImage:_originImage];
}
[self.brightnessFilter imageByFilteringImage:_originImage];
这个获取处理后图片的方法是否正确,看到stackoverflow上的回答都是[self.brightnessFilter imageFromCurrentlyProcessedOutput]
这样来获取的,但这个方法貌似已经弃用了,哪种方法才是正确的,还是我前面的代码也有问题?iPhone 5s真机调试发现实时的调整会存在卡顿的现象,但原始图片质量并不是很高,尝试过异步的方案,仍然会出现卡顿,具体要如何处理才能避免这种情况?
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.brightnessFilter setBrightness:[brightnessSlider value]];
dispatch_async(dispatch_get_main_queue(), ^{
self.editImageView.image = [self.brightnessFilter imageByFilteringImage:_originImage];
});
});
[self.brightnessFilter imageByFilteringImage:_originImage]这句可能也会阻塞主线程。
改成下面这样试试呢