Puzzling CGBitmapImageCreate problem
Puzzling CGBitmapImageCreate problem
- Subject: Puzzling CGBitmapImageCreate problem
- From: Florent Pillet <email@hidden>
- Date: Tue, 12 Aug 2003 11:07:54 +0200
I'm trying to recolor a NSImage using a fixed palette. Nothing fancy,
just recoloring. For that matter, I use a CGBitmapContext with the
intent of using an indexed color space, so that CoreGraphics performs
the recolorization for me (am I lazy or what? ;-))
The problem is that CGBitmapContextCreate returns NULL when created
with a CGColorSpaceRef which is an indexed palette. Here is what fails:
// create a CGColorSpace which uses the given palette
CGColorSpaceRef rgbCS = CGColorSpaceCreateDeviceRGB();
CGColorSpaceRef paletteCS = CGColorSpaceCreateIndexed(rgbCS,
numColors-1, colorTable);
// prepare the buffer holding the image in the CGContext
unsigned char *bmpData = malloc(width * height * 4);
memset(bmpData, 0xff, width * height * 4); // all white and alpha
channel set
// create a CGContext into which we will draw the image
CGContextRef bmpContext = CGBitmapContextCreate(bmpData, width,
height, 8, width * 4, paletteCS, kCGImageAlphaPremultipliedLast);
Here, bmpContext is NULL. If I replace paletteCS with rgbCS, the
context is properly created and my subsequent operations work fine.
Any hint at what the trouble is? The docs don't say that you
can't/shouldn't use an indexed color space to create a bitmap context...
Thanks for any help,
Florent.
--
Florent Pillet, Code Segment email@hidden
Developer tools and end-user products for Palm OS & Mac OS X
ICQ: 117292463
http://perso.wanadoo.fr/fpillet
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.