Как сделать UIImage темнее?

Я могу найти в сети множество руководств, которые делают UIImage в оттенках серого. Но я просто хочу, чтобы UIImage был немного темнее и все еще красочнее. Это возможно? Если да, пожалуйста, дайте мне несколько примеров источников.

Спасибо.


person Nguyen Minh Binh    schedule 15.01.2013    source источник
comment
См. этот ответ: stackoverflow.com/questions/12380288/   -  person Kyle    schedule 15.01.2013
comment
Как насчет этого - stackoverflow.com/questions/8098130/   -  person alex    schedule 15.01.2013
comment
это будет хорошее начало для вас...   -  person holex    schedule 15.01.2013


Ответы (2)


Вам следует изучить фильтры Core Image — вот Документы Apple

(... или вы могли бы просто следовать ответу Аттилы, намного проще!)

person foundry    schedule 15.01.2013

Спасибо Zenox, это решение отлично работает:

+ (UIImage *)colorizeImage:(UIImage *)image withColor:(UIColor *)color {
    UIGraphicsBeginImageContext(image.size);

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);

    CGContextScaleCTM(context, 1, -1);
    CGContextTranslateCTM(context, 0, -area.size.height);

    CGContextSaveGState(context);
    CGContextClipToMask(context, area, image.CGImage);

    [color set];
    CGContextFillRect(context, area);

    CGContextRestoreGState(context);

    CGContextSetBlendMode(context, kCGBlendModeMultiply);

    CGContextDrawImage(context, area, image.CGImage);

    UIImage *colorizedImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return colorizedImage;
}
person Nguyen Minh Binh    schedule 16.01.2013