2014-11-06 38 views
1

任何人都知道如何更新此代碼的iOS 8?我收到此錯誤信息:iOS 8 CGContextRef不受支持的參數組合

每行

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaPremultipliedFirst; 4294967289 bytes/row.

CGContextRef CreateBitmapContenxtFromSizeWithData(CGSize s, void* data) 
{ 
    int w = s.width, h = s.height; 
    int bitsPerComponent = 8; 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    int components = 4; 
    int bytesPerRow = (w * bitsPerComponent * components + 7)/8; 

    CGContextRef result = CGBitmapContextCreate(data, w, h, 8, bytesPerRow, colorSpace, (CGBitmapInfo)kCGImageAlphaPremultipliedFirst); 
    CGColorSpaceRelease(colorSpace); 
    return result; 
} 
+0

沒有人知道如何做到這一點? – mikomi 2014-11-08 16:02:02

回答

0

字節在上面的代碼中錯誤地計算。

要計算每行的字節數,您可以將圖像的寬度乘以每像素的位數,這在您的情況下似乎爲四位。

int bytesPerRow = w * 4; 

不過要小心,如果data點到的圖像數據存儲在RGB,你必須每像素三個字節。您還需要將CGImageAlphaInfo.NoneSkipFirst標誌作爲最後一個參數傳遞給CGBitmapContextCreate,以便省略Alpha通道。

相關問題