Search code examples
iphone-sdk-3.0uiimagemaskcgimagecgimagemaskcreate

Replace all white/nearly white pixels in a UIImage with alpha using CGImage?


I have a UIImage with white background. I would like replace the white background/pixels with alpha-transparent pixels. I've looked at other questions on StackOverflow, along with Quartz documentation, but have yet to find a coherent "start-to-end" for this problem. How is this done?


Solution

  • CGImageCreateWithMaskingColors
    

    A UIImage wraps a CGImage. Take the CGImage, run it through CGImageCreateWithMaskingColors, then either create a new UIImage from the result or assign the result back to the UIImage.