Как обесцветить UIImage?

Есть ли простой способ (или встроенная библиотека) в iOS 5.x для обесцвечивания 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

Это кажется немного сложнее чем я ожидал. Есть ли более простой способ, чем этот?

Я думал об основном изображении, но не могу найти конкретного примера того, как с его помощью обесцветить изображение.

10
задан Brad Larson 6 June 2012 в 03:48
поделиться