1

I have an image that is totally white in its RGB components, with varying alpha -- so, for example, 0xFFFFFF09 in RGBA format. But when I load this image with either UIImage or CGImage APIs, and then draw it in a CGBitmapContext, it comes out grayscale, with the RGB components set to the value of the alpha -- so in my example above, the pixel would come out 0x09090909 instead of 0xFFFFFF09. So an image that is supposed to be white, with varying transparency, comes out essentially black with transparency instead. There's nothing wrong with the PNG file I'm loading -- various graphics programs all display it correctly.

I wondered whether this might have something to do with my use of kCGImageAlphaPremultipliedFirst, but I can't experiment with it because CGBitmapContextCreate fails with other values.

The ultimate purpose here is to get pixel data that I can upload to a texture with glTexImage2D. I could use libPNG to bypass iOS APIs entirely, but any other suggestions? Many thanks.

RedMarbleGames
  • 121
  • 2
  • 6
  • Is this question already outdated? If not, could you provide the code to load the image in a sample project in order to reproduce the problem? – Kjellski Jan 17 '12 at 21:48
  • Thanks for the offer. I couldn't figure this out, so dropped the use of the CGImage APIs, and just load images with libpng directly. – RedMarbleGames Jan 26 '12 at 20:45

1 Answers1

0

White on a black background with an alpha of x IS a grey value corresponding to x in all the components. Thats how multiplicative blending works.

Goz
  • 61,365
  • 24
  • 124
  • 204
  • 1
    Thanks for the answer, but it doesn't really address the question, which is about how to maintain the integrity of the data loaded from the file *without* multiplicative blending. When I load this graphic in an image editor, it is a gradually fading white image -- no grey at all. But iOS changes the data as it is loaded, and that's what I'm trying to avoid. – RedMarbleGames Aug 18 '11 at 01:39