2009-06-24 5 views
2

J'essaie de comprendre comment créer un contexte bitmap avec un espace colorimétrique CMJN et y dessiner une image.Est-il possible de créer un CGBitmapContext avec un espace colorimétrique CMJN et de dessiner dedans?

J'utilise le code de Q & d'Apple A here, et l'a modifié pour créer l'espace de couleurs CMYK et dessiner dedans. Dans mes journaux, je reçois l'erreur

Description de pixels non pris en charge - 4 composants, 8 bits par composante, 32 bits par pixel

et je reçois un contexte null retourné.

Qu'est-ce qui me manque? Ceci est le code que je suis en train de courir:

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; 

Merci à l'avance! -SYU

Répondre

1

Il n'y a pas de contextes bitmap CMY sur iPhone OS. Mais il n'y a pas non plus de documentation sur les formats de pixels pris en charge sur l'iPhone, only for Mac OS. C'est essai et erreur :(

+0

C'est à peu près ce que j'ai pensé. –

Questions connexes