【问题标题】:Adjusting image brightness without using third party library in iOS在 iOS 中不使用第三方库调整图像亮度
【发布时间】:2014-07-17 13:04:25
【问题描述】:

我正在开发一个应用程序,用户将在其中从设备 (UIImagePickerController) 捕获图像并可以稍后对其进行编辑。但我被困在图像的亮度部分。因为我不想使用任何第三方库,如 GPUImage 或 GLImageProcessing,因为我已经使用了很多第三方库。所以有人可以帮助我通过代码增加或减少图像亮度。任何帮助将不胜感激。

谢谢。

【问题讨论】:

    标签: ios7 uiimagepickercontroller


    【解决方案1】:

    一种方法是您可以使用仅苹果支持的 CoreImage 框架。以下是您可以使用的代码:-

    - (void) CIColorControls :(float)saturation
    {
    
     CIImage *inputImage =[[CIImage alloc]initWithImage:imageView.image];
    
    //initialize filter for brightness
    CIFilter *brightnesContrastFilter = [CIFilter filterWithName:@"CIColorControls"];
    [brightnesContrastFilter setDefaults];
    [brightnesContrastFilter setValue: inputImage forKey: @"inputImage"];
    [brightnesContrastFilter setValue:[NSNumber    numberWithFloat:0.5f]forKey:@"inputBrightness"];
    [brightnesContrastFilter setValue: [NSNumber numberWithFloat:saturation]forKey:@"inputSaturation"];
    [brightnesContrastFilter setValue: [NSNumber numberWithFloat:2.0f]forKey:@"inputContrast"];
    CIImage *outputImage = [brightnesContrastFilter valueForKey: @"outputImage"];
    CIContext *context = [CIContext contextWithOptions:nil];
    imageView.image = [UIImage imageWithCGImage:[context
                                                    createCGImage:outputImage
                                                    fromRect:outputImage.extent]];
    

    }

    & 在滑块的动作上,你可以像

    一样调用这个方法
    -(void)colorsliderAction: (id)sender
    {
       float b;
       NSLog(@"%f",colorSlider.value);
      b=(float)colorSlider.value;
      [self CIColorControls:b];
    
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-29
      • 2012-03-27
      • 2019-03-26
      • 1970-01-01
      • 2021-08-20
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多