Ios8 iOS 8 CGContextRef不支持的参数组合
有人知道如何为iOS 8更新此代码吗?我收到以下错误消息:Ios8 iOS 8 CGContextRef不支持的参数组合,ios8,cgcontextref,Ios8,Cgcontextref,有人知道如何为iOS 8更新此代码吗?我收到以下错误消息: CGBitmapContextCreate:不支持的参数组合:8个整数位/分量;32位/像素;三分量颜色空间;KCGIMAGEAlphaPremultipledFirst;4294967289字节/行。 CGContextRef CreateBitmapContenxtFromSizeWithData(CGSize s, void* data) { int w = s.width, h = s.height; int b
CGBitmapContextCreate:不支持的参数组合:8个整数位/分量;32位/像素;三分量颜色空间;KCGIMAGEAlphaPremultipledFirst;4294967289字节/行。
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
int bytesPerRow = w * 4;
但是要小心,如果
data
指向存储在RGB中的图像数据,则每个像素有三个字节。您还需要将cgmagealphainfo.NoneSkipFirst
标志作为最后一个参数传递给CGBitmapContextCreate,以便省略alpha通道 没人知道怎么做?