How to mask a UIImage so that white becomes transparent on iphone?

You could try making the starting UIImage completely transparent and then have another UIImageView behind it that is completely white.

You're going to have to get at the raw data, look for white pixels, modify the alpha of those pixels and save to a new NSData object and then convert that to a PNG. It's not difficult, but I wouldn't call it trivial.

Try something like this... CGImageRef myMaskedImage = myImage CGImage; const float whiteMask6 = { 255,255,255, 255,255,255 }; CGImageRef myColorMaskedImage = CGImageCreateWithMaskingColors(image, whiteMask); CGDataProviderRef provider; CGImageRef myPngImage = CGImageCreateWithPNGDataProvider(provider, NULL, true, kCGRenderingIntentDefault); NSDictionary *options = NSDictionary dictionaryWithObjectsAndKeys:NSNumber numberWithInt: 72, kCGImagePropertyDPIHeight, NSNumber numberWithInt: 72, kCGImagePropertyDPIWidth, nil; CGImageDestinationRef destRef = CGImageDestinationCreateWithURL ((CFURLRef)outPath, (CFStringRef)@"image. Png" , 1, NULL); CGImageDestinationAddImage(destRef, myPngImage, (CFDictionaryRef)options); CGImageDestinationFinalize(destRef); CGRelease(destRef); CGImageRelease(myColorMaskedImage); CGImageRelease(myPngImage); from the rather long winded Quartz2d Programming Guide and this mailing list message.

I have a UIImage (generated by a user drawing) that has a white background. I'd like to make the white portions of this image transparent. I'd also like to save this to a PNG file.

I've looked around on forums but can't figure out how to mask the image correctly. Has anyone tried this before?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions