PDA

View Full Version : CGImage with ColorMask, transparant is black?




StijnSpijker
Jul 4, 2009, 12:07 AM
Heya,

I've got an image (a single frame GIF, no animation), that has transparancy.
But when I add the UIImage to my IBOutlet UIImageView as a subview, the transparant part of my image is displayed black!?

This is how I made the transparant part of my image masked:

float trans = [[GIF_transparancies objectAtIndex:index] floatValue]; // This gets the color that should be transparant.
CGFloat colorMasking[6] = {trans, trans}; // Adding this 6 times (R, G , B) does not help/work, same effect -> black parts instead of transparant.

UIImage *image = [UIImage imageWithData:[GIF_framesData objectAtIndex:index]]; // Get the GIF and make an image out of it.
CGImageRef imageWithTransparancy = CGImageCreateWithMaskingColors([image CGImage], colorMasking); // Color mask it.

return [UIImage imageWithCGImage:imageWithTransparancy]; // Turn it back into a UIImage


So the 'colormasking' part works, the parts that I expected to be transparant become black.
Now I just want the black to become transparant :p...

Any help?



kainjow
Jul 5, 2009, 11:02 PM
I would double-check the docs on the 2nd arg to the CGImageCreateWithMaskingColors function and make sure you're passing it the right data for the colorspace of the image.

Also you should CGImageRelease the image after creating the UIImage from it.