Change color of image to transparent

C

CGImageRef rawImageRef = image.CGImage;

const double colorMasking[6] = { 0, 0, 0, 0, 0, 0 };

UIGraphicsBeginImageContext(image.size);

 

CGImageRef maskedImageRef =  CGImageCreateWithMaskingColors(rawImageRef, colorMasking);

{

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();

 

About the author

yogita.balganure
By yogita.balganure

Category