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?
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?