kCGColorSpaceGenericRGB is deprecated on iPhone?

会有一股神秘感。 提交于 2019-12-03 15:35:48

问题


I'm trying to get bitmap context with the following code:

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
}

A warning says:'kCGColorSpaceGenericRGB' is deprecated.

Does this mean that colorSpace is unchangeable? If that is true, we'll be unable to change the color data of any images using colorSpace. And how to process image then?


回答1:


The generic color space is deprecated. Instead try;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();



来源:https://stackoverflow.com/questions/560254/kcgcolorspacegenericrgb-is-deprecated-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!