PDA

View Full Version : CGImageCreateWithMaskingColor - I'm not understand the MaskingColor Array parameter..


damaged1130
2006.08.25, 03:27 AM
I can't see to figure out how to use CGImageCreateWithMaskingColor

It seems that no matter what array I pass to it for masked colors it will not mask properly. I think I just fundementally don't understand the MaskedColors array...


CGImageRef image, subImage, maskedImage;
CGDataProviderRef provider;
CFStringRef path;
CFURLRef url;
CGRect myImageArea;


myImageArea = CGRectMake( ((image_num * SPRITE_WIDTH) % (SPRITE_WIDTH * SPRITE_COLUMNS)), (((int)(image_num / SPRITE_COLUMNS)) * SPRITE_HEIGHT), SPRITE_WIDTH, SPRITE_HEIGHT);

path = CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, NULL);

CFRelease(path);
provider = CGDataProviderCreateWithURL(url);

CFRelease(url);
image = CGImageCreateWithJPEGDataProvider(provider,
NULL,
true,
kCGRenderingIntentDefault);
CGDataProviderRelease(provider);

const float myMaskingColors[6] ={255, 255, 255, 255, 255, 255};
subImage = CGImageCreateWithImageInRect(image, myImageArea);
maskedImage = CGImageCreateWithMaskingColor(subImage, myMaskingColors);
CGContextDrawImage(myContext, myContextRect, maskedImage);
CGImageRelease(image);
CGImageRelease(subImage);
CGImageRelease(maskedImage);


The above code should create an image that is transparent everywhere that there is white. but it does pretty much nothing... If I change it to:


const float myMaskingColors[6] ={0, 255, 0, 255, 0, 255};


I expect the above mask to grab "EVERY" color but it seems to only grab random black spots in the picture? Can anyone re-educate me to what newb mistake I am making with myMaskingColors and advise how to set it up to grab white out of jpeg images?

Jones
2006.08.25, 08:01 PM
If what you mean by "random black spots" is a form of splotching being masked out, and others not, it's probably because your image is antialiased in some way that introduces variants of the color you want to use as masks.

That sounds logical, if I interpreted your post correctly.

damaged1130
2006.08.25, 08:28 PM
I guess the real question is though why am I getting the spottedness when using a mask of 0,255,0,255,0,255. When that should mask every color between 0,0,0 and 255,255,255 IE: every color. but instead it is only masking a few. And furthermore why 255,255,255,255,255,255 for a masking color range is not masking white at all.

If I understand correctly a jpeg is a 24 bit image so it has 8bits for each RGB so 0,255 ,0,255,0,255 should catch everything in the image instead of just parts of the image.