2012-07-31 124 views
1
CGContextRef context = CGBitmapContextCreate(nil, 
     width, //if width More than 6002/4 
     height, 
     8, 
     width*4,//if width*4 > 6002 
     colorSpace, 
     kCGImageAlphaPremultipliedFirst |kCGBitmapByteOrder32Little); 

我想建立一个大的位图(宽度< = 2500)时宽度* 4> 6002具有用于IOS CGBitmapContextCreate大的位图

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

如何建立一个大的位图 感谢一个错误。

回答

1

问题是6002字节/行,因为每个像素在这里需要4个字节,但6002不能被4除尽而不剩余。更好地计算每个像素的行:

size_t width = 1920; 
size_t height = 1080; 
CGContextRef context = CGBitmapContextCreate(
    NULL, 
    width, 
    height, 
    8, 
    width * 4, 
    colorSpace, 
    kCGImageAlphaPremultipliedFirst |kCGBitmapByteOrder32Little); 
+0

非常感谢,我现在能做到这一点 – zt9788 2012-08-02 07:16:03

0

new bytesPerRow将与原始图像不同。你需要计算新的bytesPerRow。

bytesPerPixel * targetWidth

你不能把静态8和4

参考this的色彩空间和相对bytesPerPixel。

+0

谢谢,但我不明白,你可以给我一些代码来构建一个大的位图 – zt9788 2012-07-31 11:53:24