I am creating a transparent image on iOS using Quartz. However, this image shows up with the proper transparency in the Simulator, but shows a white background on a device.
Here is the code I’m using for this:
+ (UIImage *)clearRect:(CGRect)rect inImage:(UIImage *)image {
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions([image size], NO, 0.0);
else
UIGraphicsBeginImageContext([image size]);
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawInRect:CGRectMake(0.0, 0.0, [image size].width, [image size].height)];
CGContextClearRect(context, rect);
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
NSData *data= UIImagePNGRepresentation(result);
UIImage *img = [UIImage imageWithData:data];
UIGraphicsEndImageContext();
return img;
}
This is what I’m seeing on the device:

What could I be doing wrong?
Given that the code works in the simulator and not your device you may have become victim to the cruftmonster described below:
http://weblog.bignerdranch.com/642-beware-the-cruftmonster/
You may have some legacy files that have been removed from your Xcode project but not the application bundle on the device. Did you initially test with opaque images?
Not sure if this is the solution, but it certainly matches the symptoms you describe.