Ändern der Farbe von UIImage

Ich versuche es zu ändern Farbe von UIImage. Mein code:

-(UIImage *)coloredImage:(UIImage *)firstImage withColor:(UIColor *)color {
    UIGraphicsBeginImageContext(firstImage.size);

    CGContextRef context = UIGraphicsGetCurrentContext();
    [color setFill];

    CGContextTranslateCTM(context, 0, firstImage.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    CGContextSetBlendMode(context, kCGBlendModeCopy);
    CGRect rect = CGRectMake(0, 0, firstImage.size.width, firstImage.size.height);
    CGContextDrawImage(context, rect, firstImage.CGImage);

    CGContextClipToMask(context, rect, firstImage.CGImage);
    CGContextAddRect(context, rect);
    CGContextDrawPath(context,kCGPathElementMoveToPoint);

    UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return coloredImg;
}

Dieser code funktioniert, aber erhalten Bild ist nicht so gut wie sein soll: bounds Pixel Bild zurückgegeben werden intermittierende und nicht so glatt wie in meinem ersten Bild. Wie kann ich dieses problem beheben?

InformationsquelleAutor der Frage RomanHouse | 2012-10-13

Schreibe einen Kommentar