iOS 图片处理问题
迷茫
迷茫 2017-04-17 16:38:44
0
2
508

比如对图片进行实时亮度调整

用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];
        
}
  1. [self.brightnessFilter imageByFilteringImage:_originImage];这个获取处理后图片的方法是否正确,看到stackoverflow上的回答都是[self.brightnessFilter imageFromCurrentlyProcessedOutput]这样来获取的,但这个方法貌似已经弃用了,哪种方法才是正确的,还是我前面的代码也有问题?

  2. 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];
        });
    });
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
刘奇
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] may also block the main thread.

Change it to the following and try it

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self.brightnessFilter setBrightness:[brightnessSlider value]];
        UIImage *image = [self.brightnessFilter imageByFilteringImage:_originImage];
        dispatch_async(dispatch_get_main_queue(), ^{
            self.editImageView.image = image;
        });
    });
黄舟

You actually use the valueChangeAction: method. When you drag the slider, this method will be called continuously, and then the image will be processed continuously. It is strange that it is not stuck. You should use UIControlEventTouchUpInside to process the image when the drag is completed. . If you must use UIControlEventValueChanged, then do the processing in valueChangeAction.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template