【问题标题】:iOS sdk, render image from unsigned char array, CGBitmapContextCreate returns NULLiOS sdk,从无符号字符数组渲染图像,CGBitmapContextCreate 返回 NULL
【发布时间】:2011-08-20 13:43:50
【问题描述】:

我有一个具有以下值的 unsigned char* 数据,如在 xcode 中调试时所见,

\xc1\xc1\xc1\xc1\xc1\xc1\xc1\xc0\x84\x03\x03\x02\x03\x02\x03\x03\x03\x02\x02\x03\x02\x03 \x02\x02\x03\x02\x02\x02\x02\x03\x03\x03\x03\x03\x02\x02\x03\x03\x03\x02\x02\x03\x02\x02\x02\x02\x03 \x03\x03\x02\x02\x02\x02\x03\x02\x03\x02\x03\x02\x03\x02\x03\x02\x03\x02\x02\x02\x03\x03\x03\x03\x03 \x02\x03\x02\x03\x02\x03\x03\x02\x02\x03\x03\x03\x02\x02\x02\x02\x02\x03\x02\x02\x03\x02\x03\x02\x02 \x03\x03\x03

这是二维码的数据数组。

符号数据表示为包含宽度*宽度 uchars 的数组。每个 uchar 代表一个模块(点)。如果 uchar 的低位为 1,则对应的模块为黑色。

在上述情况下,宽度为 177

我在 CGBitmapContextCreate 中尝试了各种组合,但似乎总是得到 NULL。

请指教。

您的帮助将不胜感激。

【问题讨论】:

    标签: xcode ios ios4 cgbitmapcontextcreate cgbitmapcontext


    【解决方案1】:

    我已经成功使用了:

    CGImageRef refImage = [myUIImage CGImage];
    CGContextRef ctx;
    int w = CGImageGetWidth(refImage);
    int h = CGImageGetHeight(refImage);
    int bytesPerRow = CGImageGetBytesPerRow(refImage);
    ctx = CGBitmapContextCreate(rawData,
                                w,
                                h,
                                8,
                                bytesPerRow,
                                CGImageGetColorSpace( refImage ),
                                kCGImageAlphaPremultipliedLast ); 
    
    // Fill in rawData, which is the unsigned char pixel array
    
    refImage = CGBitmapContextCreateImage (ctx);
    UIImage* myUIImage2 = [UIImage imageWithCGImage:refImage];  
    
    CGContextRelease(ctx); 
    CGImageRelease(refImage);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-11
      • 2018-07-14
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多