iPhone上不推荐使用kCGColorSpaceGenericRGB?

Chi*_*ong 16 iphone cocoa image core-graphics colors

我正在尝试使用以下代码获取位图上下文:

GContextRef MyCreateBitmapContext (int pixelsWide, int pixelsHigh)
{
    CGContextRef    context = NULL;
    CGColorSpaceRef colorSpace;
    void *          bitmapData;
    int             bitmapByteCount;
    int             bitmapBytesPerRow;

    bitmapBytesPerRow   = (pixelsWide * 4);                          // 1
    bitmapByteCount     = (bitmapBytesPerRow * pixelsHigh);

    colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);// 2
    bitmapData = malloc( bitmapByteCount );                          // 3
    if (bitmapData == NULL)
    {
        fprintf (stderr, "Memory not allocated!");
        return NULL;
    }

    context = CGBitmapContextCreate (bitmapData,                     // 4
                                    pixelsWide,
                                    pixelsHigh,
                                    8,      // bits per component
                                    bitmapBytesPerRow,
                                    colorSpace,
                                    kCGImageAlphaPremultipliedLast);
    if (context== NULL)
    {
        free (bitmapData);                                          // 5
        fprintf (stderr, "Context not created!");
        return NULL;
    }

    CGColorSpaceRelease( colorSpace );                              // 6
    return context;                                                 // 7
}
Run Code Online (Sandbox Code Playgroud)

警告说:'kCGColorSpaceGenericRGB' is deprecated.

这是否意味着colorSpace不可改变?如果是这样,我们将无法使用更改任何图像的颜色数据colorSpace.那么如何处理图像呢?

And*_*ant 35

不推荐使用通用颜色空间.相反,尝试;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();