gpt4 book ai didi

objective-c - 在 Mac 上使用 ZXingObjC 创建二维码

转载 作者:搜寻专家 更新时间:2023-10-30 19:41:43 26 4
gpt4 key购买 nike

我正在尝试使用 http://github.com/TheLevelUp/ZXingObjC 在我的 Mac 应用程序上创建二维码。

它适用于所有条形码类型,但在 QRcode 上返回 nil! “结果”和“错误”都是空的。这是我的代码:

NSError* error = nil;
ZXMultiFormatWriter* writer = [[ZXMultiFormatWriter alloc] init];
ZXBitMatrix* result = [writer encode:@"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
format:kBarcodeFormatQRCode
width:1750
height:1750 hints:[[ZXEncodeHints alloc] init] error:&error];
if (result) {
CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage];
self.image.image = [[NSImage alloc] initWithCGImage:image size:NSMakeSize(1750, 1750)];
} else {

NSLog(@"error: %@", error);
}

这是怎么回事?

最佳答案

我遇到了同样的问题。这是解决方法。

  1. 打开文件ZXingObjC\qrcode\encoder\ZXEncoder.m

  2. 找到这一行:int minPenalty = NSIntegerMax;。必须有一个警告:从'long'到'int'的隐式转换将 9223372036854775807 更改为 -1。这就是问题的原因。 NSIntegerMax 在我的 64 位 Mac 上返回 9223372036854775807 并且 minPenalty 获得 -1 值(因为 int 类型不能存储这么大的数字)。

  3. NSIntegerMax 替换为 INT_MAX。它应该返回正确的值:2147483647。这是根据对 this question 的回答在 32 位机器上返回的数字 NSIntegerMax .

  4. 运行应用程序,您将获得二维码!

关于objective-c - 在 Mac 上使用 ZXingObjC 创建二维码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16024161/

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