在iOS 5.x中是否有簡單的方法(或內置庫)來使UIImage飽和?以下是我目前的工作方式:我如何去除UIImage的色差?
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, self.bounds.size.height); // flip image right side up
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, self.image.CGImage);
CGContextSetBlendMode(context, kCGBlendModeSaturation);
CGContextClipToMask(context, self.bounds, image.CGImage); // restricts drawing to within alpha channel
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, desaturation);
CGContextFillRect(context, rect);
CGContextRestoreGState(context); // restore state to reset blend mode
這似乎比我預期的要複雜一些。有沒有比這更簡單的方法?
我正在考慮核心圖像,但我似乎無法找到一個具體的例子,如何使用它去飽和圖像。
不確定,但可以嘗試應用[CIFilter](http://developer.apple.com/library/ios/#DOCUMENTATION/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIFilter_Class/Reference/Reference.html) [kCICategoryColorEffect](http://developer.apple.com/library/ios/DOCUMENTATION/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIFilter_Class/Reference/Reference.html#//apple_ref/doc/c_ref/kCICategoryColorEffect)類型。快速演示如何應用CIFilter:http://iazapps.wordpress.com/2012/02/01/applying-cifilter-on-image-in-an-uiimageview/ –
什麼是你的去飽和值? – malhal
indiekiduk,該代碼出現在更多上下文中的答案在這裏:http://stackoverflow.com/questions/1144768/how-can-i-change-the-saturation-of-an-uiimage(去飽和是在例)。 – JLundell