【问题标题】:IOS CGBitmapContextCreate Large bitmapIOS CGBitmapContextCreate大位图
【发布时间】:2012-07-29 04:10:42
【问题描述】:
CGContextRef context =  CGBitmapContextCreate(nil,
        width, //if width More than 6002/4
        height, 
        8,
        width*4,//if width*4 > 6002
        colorSpace,
        kCGImageAlphaPremultipliedFirst |kCGBitmapByteOrder32Little );

当宽度*4>6002 有错误时,我想构建一个大位图(宽度

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

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

【问题讨论】:

    标签: objective-c ios bitmap gdi


    【解决方案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 );
    

    【讨论】:

      【解决方案2】:

      新的 bytesPerRow 将不同于原始图像。您需要计算新的 bytesPerRow。

      bytesPerPixel * 目标宽度

      你不能接受静态 8 和 4。

      请参阅this 以了解颜色空间和相对字节每像素。

      【讨论】:

      • 谢谢,但我不明白,你能给我一些代码来构建一个大的位图
      猜你喜欢
      • 1970-01-01
      • 2016-05-22
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2017-11-23
      相关资源
      最近更新 更多