CGImage with ColorMask, transparant is black?

Discussion in 'iOS Programming' started by StijnSpijker, Jul 3, 2009.

  1. StijnSpijker macrumors newbie

    Joined:
    Jan 27, 2009
    Location:
    The Netherlands
    #1
    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:
    Code:
    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?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     

Share This Page