1

このコードを iOS 8 用に更新する方法を知っている人はいますか? 次のエラー メッセージが表示されます。

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;
}
4

1 に答える 1

0

上記のスニペットでは、1 行あたりのバイト数が正しく計算されていません。

行あたりのバイト数を計算するには、画像の幅を取り、ピクセルあたりのビット数を掛けるだけです。この場合、4 のようです。

int bytesPerRow = w * 4;

dataただし、 RGB で格納されている画像データを指す場合は、1 ピクセルあたり 3 バイトになることに注意してください。CGImageAlphaInfo.NoneSkipFirstまた、フラグを CGBitmapContextCreate の最後のパラメーターとして渡す必要があるため、アルファ チャネルは省略されます。

于 2015-08-30T09:00:42.170 に答える