简体   繁体   English

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

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

I have an unsigned char* data with the following values, as seen while debugging in xcode, 我有一个具有以下值的无符号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 \\ 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

This is the data array for a qr code. 这是二维码的数据数组。

Symbol data is represented as an array contains width*width uchars. 符号数据表示为包含width * width uchars的数组。 Each uchar represents a module (dot). 每个uchar代表一个模块(点)。 If the less significant bit of the uchar is 1, the corresponding module is black. 如果uchar的较低有效位为1,则对应的模块为黑色。

In the above case the width is 177 . 在上述情况下,宽度为177

I have tried various combination in CGBitmapContextCreate, but always seem to get NULL. 我曾尝试在CGBitmapContextCreate中进行各种组合,但始终似乎会得到NULL。

Please advise. 请指教。

Your help will be much appreciated. 您的帮助将不胜感激。

I have successfully used : 我已经成功使用了:

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