R – Transparent color works on the simulator but becomes black on the iPhone

cocoa-touchimageiphonetransparency

I am trying to draw an image that has some transparent regions.
I load the image using

image = [UIImage imageNamed:@"testimage.png"];

and draw it using

[image drawAtPoint:CGPointMake(0,0)];

The UIView on which I draw the image is not opaque (and it has a transparent background color).

The problem is that everything works fine on the simulator, but when I run the app on my iPhone the transparent color becomes black! Can anyone pinpoint my error?

Best Answer

The correct answer to this problem is the .PNG format you are saving your image with. If you save as PNG-8, you will run into this problem more often that not, since it only supports 1 transparent color. If you open your .PNG file and then re-save it as a 24-bit format, you will gain genuine transparency.

Reference this thread for discussion and clarification.

  • EDIT: Just to be clear, .PNG does not have an 'alpha channel', so Chris' answer is misleading. Just be sure to save in 24-bit format with transparency enabled.
Related Topic