2009-02-18 32 views
16

我試圖讓位圖上下文中有下面的代碼:kCGColorSpaceGenericRGB在iPhone上已棄用?

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 
} 

警告說:'kCGColorSpaceGenericRGB' is deprecated.

這是否意味着colorSpace是不變的?如果是這樣,我們將無法使用colorSpace更改任何圖像的顏色數據。那麼如何處理圖像呢?

回答

35

不推薦使用通用色彩空間。反而嘗試;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

+6

thx爲答案我愛你 – Unreality 2009-08-18 07:50:04