Masking to Transparent returns empty image

Posted by Tibi on Stack Overflow See other posts from Stack Overflow or by Tibi
Published on 2010-05-28T09:19:12Z Indexed on 2010/05/28 9:21 UTC
Read the original article Hit count: 264

Filed under:
|

Hi there, I'm trying to put white color in my images to transparent with the following code. Problem is that "CGImageRef maskedTransparent" is blank. I don't understand because the code I'm using is nearly a copy paste from the doc ... Any idea ?


  • (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage { CGImageRef maskRef = maskImage.CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false);

CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);

//Array defining min & max RGB values to be transformed to transparent colors. float maskingMinMax[6] = {255, 255, 255, 255, 255, 255};

//masking image to remove range in maskinLinMax CGImageRef maskedTransparent = CGImageCreateWithMaskingColors(masked, maskingMinMax);

return [UIImage imageWithCGImage:maskedTransparent];

}


© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about transparency