Можно ли создать CGBitmapContext с цветовым пространством CMYK и рисовать в нем? - PullRequest
2 голосов
/ 24 июня 2009

Я пытаюсь выяснить, как создать растровый текст с цветовым пространством CMYK и нарисовать в нем изображение.

Я использую код из Q & A от Apple здесь и изменил его, чтобы создать цветовое пространство CMYK и рисовать в нем В своих логах я получаю ошибку

Неподдерживаемое описание пикселей - 4 компонента, 8 бит на компонент, 32 бита на пиксель

и я возвращаю нулевой контекст.

Чего мне не хватает? Вот код, который я пытаюсь запустить:

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;

Заранее спасибо! -Syu

1 Ответ

1 голос
/ 24 июня 2009

В iPhone OS нет растровых контекстов CMY. Но также нет документации о том, какие форматы пикселей поддерживаются на iPhone, только для Mac OS Это метод проб и ошибок: (

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...