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

在上面的代码片段中,每行的字节数计算不正确。

要计算每行的字节数,您只需将图像的宽度乘以每个像素的位数,在您的情况下似乎是四。

int bytesPerRow = w * 4;

不过要小心,如果data指向以 RGB 格式存储的图像数据,则每个像素有 3 个字节。您还需要将CGImageAlphaInfo.NoneSkipFirst标志作为最后一个参数传递给 CGBitmapContextCreate,以便省略 alpha 通道。

于 2015-08-30T09:00:42.170 回答