如何更改UIImage的饱和度? [英] How can I change the saturation of an UIImage?
本文介绍了如何更改UIImage的饱和度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UIImage,想要移动它的饱和度约+ 10%。是否有标准方法或函数可以用于此?
I have an UIImage and want to shift it's saturation about +10%. Are there standard methods or functions that can be used for this?
推荐答案
有一个CoreImage过滤器。 CIColorControls
只需将 inputSaturation
设置为< 1.0去饱和或> 1.0以增加饱和度...
There's a CoreImage filter for this. CIColorControls
Just set the inputSaturation
to < 1.0 to desaturate or > 1.0 to increase saturation...
eg。这是我在 UIImage
类别中添加的用于去饱和图像的方法。
eg. Here's a method I've added in a category on UIImage
to desaturate an image.
-(UIImage*) imageDesaturated {
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *ciimage = [CIImage imageWithCGImage:self.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIColorControls"];
[filter setValue:ciimage forKey:kCIInputImageKey];
[filter setValue:@0.0f forKey:kCIInputSaturationKey];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];
UIImage *image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return image;
}
这篇关于如何更改UIImage的饱和度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文