gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:49:01 26 4
gpt4 key购买 nike

我有一个具有以下值的 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

这是二维码的数据数组。

符号数据表示为包含 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);

关于xcode - iOS sdk,从无符号字符数组渲染图像,CGBitmapContextCreate 返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5918318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com