Is it possible to create a CGBitmapContext with a CMYK colorspace and draw into it?
<p>I'm trying to figure out how to create a bitmapcontext with a CMYK colorspace and draw an image into it.  </p>

<p>I'm using the code from Apple's Q&amp;A <a href="http://developer.apple.com/qa/qa2007/qa1509.html" rel="nofollow">here</a>, and modified it to create CMYK colorspace and draw into it.  In my logs, I get the error</p>

<blockquote>
  <p>Unsupported pixel description - 4 components, 8 bits-per-component, 32 bits-per-pixel</p>
</blockquote>

<p>and I get a null context returned. </p>

<p>What am I missing?  This is the code I'm trying to run:</p>

<pre><code>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;
</code></pre>

<p>Thanks in advance!
-SYU</p>
