【问题标题】:Creating QR barcodes with ZXingObjC on Mac在 Mac 上使用 ZXingObjC 创建 QR 条码
【发布时间】:2013-04-15 20:28:13
【问题描述】:

我正在尝试使用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);
}

这有什么问题?

【问题讨论】:

  • 您能否将您的二维码拆分为一个显示此问题的示例 Mac 应用程序?项目中的示例应用程序是一个 iOS 应用程序,适用于我。
  • 当然彼得,示例 iOS 示例适用于我,但在 mac 上,它不会创建条形码!我将创建一个示例项目并在此处发布以进行测试。

标签: objective-c macos cocoa qr-code


【解决方案1】:

我有同样的问题。这是解决此问题的方法。

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

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

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

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

【讨论】:

    【解决方案2】:

    尝试使用其他方法,不要使用 HINTS,仅使用:
    [writer encode:@"yourmeganumber" format:kBarcodeFormatQRCode width:xxxx height:xxxx error:&error];

    这对我有用
    试着告诉我

    【讨论】:

    • 什么会导致其中一种方法起作用而另一种方法失败?
    • 谢谢丹尼尔,我试过没有提示的,结果一样!结果和错误都是零
    猜你喜欢
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 2014-06-20
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多