My application lets the user save/load images with alpha values to the camera roll on the device. I can see in the Photos application that these images are appropriately alpha'd, as alpha'd areas just appear black. However, when I load these images back into the application using the valueForKey:UIImagePickerControllerOriginalImage
message to the info
dictionary from (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
, the alpha values are turned to just white, making those sections opaque. Is there a way to preserve these alpha values?
views:
21answers:
1
A:
Found it out! Here's my function for doing this. Your milage may vary!:
- (UIImage*)processImage:(UIImage*)image
{
CGImageRef reference = image.CGImage;
float colors[6] = {0xEE, 0xFF, 0xEE, 0xFF, 0xEE, 0xFF};
CGImageRef newimage = CGImageCreateWithMaskingColors(reference, colors);
UIImage *result = [[UIImage alloc] initWithCGImage:newimage];
CGImageRelease(newimage);
return result;
}
Peter Hajas
2010-05-20 01:49:54