Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change color of an UIImage in ios

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 381
    Comment on it

    You can pass array of colors in this function in order to change any color of an UIImage. Just pass UIColor and UIImage to this function.

    +(UIImage *)changeColorTo:(NSMutableArray*) array Transparent: (UIImage *)image
    {
        CGImageRef rawImageRef=image.CGImage;

    // const float colorMasking[6] = {222, 255, 222, 255, 222, 255}; const CGFloat colorMasking[6] = {[[array objectAtIndex:0] floatValue], [[array objectAtIndex:1] floatValue], [[array objectAtIndex:2] floatValue], [[array objectAtIndex:3] floatValue], [[array objectAtIndex:4] floatValue], [[array objectAtIndex:5] floatValue]}; UIGraphicsBeginImageContext(image.size); CGImageRef maskedImageRef=CGImageCreateWithMaskingColors(rawImageRef, colorMasking); { //if in iphone CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0.0, image.size.height); CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0); } CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.size.width, image.size.height), maskedImageRef); UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); CGImageRelease(maskedImageRef); UIGraphicsEndImageContext(); return result;

    }

    Happy Coding!!!

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: