簡體   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