繁体   English   中英

iOS SDK,从无符号字符数组渲染图像,CGBitmapContextCreate返回NULL

[英]iOS sdk, render image from unsigned char array, CGBitmapContextCreate returns NULL

我有一个具有以下值的无符号char *数据 ,如在xcode中进行调试时所看到的,

\\ xc1 \\ xc1 \\ xc1 \\ xc1 \\ xc1 \\ xc1 \\ xc1 \\ xc0 \\ x84 \\ x03 \\ x03 \\ x02 \\ x03 \\ x02 \\ x03 \\ x03 \\ x03 \\ x03 \\ x02 \\ x02 \\ x03 \\ x02 \\ x03 \\ x02 \\ x02 \\ x02 \\ x03 \\ x02 \\ x02 \\ x02 \\ x02 \\ x03 \\ x03 \\ x03 \\ x03 \\ x03 \\ x02 \\ x02 \\ x03 \\ x03 \\ x03 \\ x02 \\ x02 \\ x03 \\ x02 \\ x02 \\ x02 \\ x02 \\ x02 \\ x03 \\ 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 \\ 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

这是二维码的数据数组。

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

在上述情况下,宽度为177

我曾尝试在CGBitmapContextCreate中进行各种组合,但始终似乎会得到NULL。

请指教。

您的帮助将不胜感激。

我已经成功使用了:

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM