CoreGraphics on iPhone. What is the proper way to load a PNG file with pre-multiplied alpha?
Posted
by dugla
on Stack Overflow
See other posts from Stack Overflow
or by dugla
Published on 2010-03-29T13:21:56Z
Indexed on
2010/03/29
13:23 UTC
Read the original article
Hit count: 548
coregraphics
|iphone
For my iPhone 3D apps I am currently using CoreGraphics to load png files that have pre-multiplied alpha. Here are the essentials:
// load a 4-channel rgba png file with pre-multiplied alpha.
CGContextRef context =
CGBitmapContextCreate(data, width, height, 8, num_channels * width, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
// Draw the image into the context CGRect rect = CGRectMake(0, 0, width, height); CGContextDrawImage(context, rect, image); CGContextRelease(context);
I then go on and use the data as a texture in OpenGL.
My question: By specifying pre-multiplied alpha - kCGImageAlphaPremultipliedLast - am I - inadvertently - telling CoreGraphics to multiply the r g b channels by alpha or - what I have assumed - am I merely indicating that the format of the incoming image has pre-multiplied alpha?
Thanks, Doug
© Stack Overflow or respective owner