tags:

views:

38

answers:

1

Hi,

I'm trying to figure out how to create a bitmapcontext with a CMYK colorspace and draw an image into it.

I'm using the code from Apple's Q&A here, and modified it to create CMYK colorspace and draw into it. In my logs, I get the error

Unsupported pixel description - 4 components, 8 bits-per-component, 32 bits-per-pixel

and I get a null context returned.

What am I missing? This is the code I'm trying to run:

CGContextRef    context = NULL;
CGColorSpaceRef colorSpace;
void *          bitmapData;
int             bitmapByteCount;
int             bitmapBytesPerRow;

// Get image width, height. We'll use the entire image.
size_t pixelsWide = CGImageGetWidth(inImage);
size_t pixelsHigh = CGImageGetHeight(inImage);

// Declare the number of bytes per row. Each pixel in the bitmap in this
// example is represented by 4 bytes; 
bitmapBytesPerRow   = (pixelsWide * 4);
bitmapByteCount     = (bitmapBytesPerRow * pixelsHigh);

// Use the generic CMYK color space.
colorSpace = CGColorSpaceCreateDeviceCMYK();
if (colorSpace == NULL)
{
    fprintf(stderr, "Error allocating color space\n");
    return NULL;
}

// Allocate memory for image data. This is the destination in memory
// where any drawing to the bitmap context will be rendered.
bitmapData = malloc( bitmapByteCount );
if (bitmapData == NULL) 
{
    fprintf (stderr, "Memory not allocated!");
    CGColorSpaceRelease( colorSpace );
    return NULL;
}

// Create the bitmap context. We don't need alpha.  Regardless of what the source image format is 
// (CMYK, Grayscale, and so on) it will be converted over to the format
// specified here by CGBitmapContextCreate.
context = CGBitmapContextCreate (bitmapData,
         pixelsWide,
         pixelsHigh,
         8,      // bits per component
         bitmapBytesPerRow,
         colorSpace,
         kCGImageAlphaNone);
if (context == NULL)
{
    free (bitmapData);
    fprintf (stderr, "Context not created!");
}

// Make sure and release colorspace before returning
CGColorSpaceRelease( colorSpace );

return context;

Thanks in advance! -SYU

A: 

There are no CMY bitmap contexts on iPhone OS. But there's also no documentation about what pixel formats are supported on the iPhone, only for Mac OS. It's trial and error :(

Nikolai Ruhe
That's pretty much what I figured. Thanks anyway.
SYU