在Mac上使用ZXingObjC创建QR条形码 [英] Creating QR barcodes with ZXingObjC on Mac
问题描述
我试图使用 http://github.com/TheLevelUp/ZXingObjC 创建QR
它适用于每个条形码类型,但在QRcode上返回nil! result和error都是空的。这里是我的代码:
It works for every barcode types, but returns nil on QRcode! both 'result' and 'error' is empty. here's my code:
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);
}
它有什么问题?
推荐答案
我有同样的问题。下面是此解决办法。
I had the same issue. Here is workaround for this.
-
打开文件
ZXingObjC\qrcode\encoder\ZXEncoder。米
查找此行: INT minPenalty = NSIntegerMax;
。必须有警告:从long到int的隐式转换将9223372036854775807更改为-1 。这就是问题的原因。 NSIntegerMax
收益 9223372036854775807
在我的64位MAC和 minPenalty
gets -1
value(因为 int
类型不能存储这么大的数字)。
Find this row: int minPenalty = NSIntegerMax;
. There must be a warning on it: Implicit conversion from 'long' to 'int' changes 9223372036854775807 to -1. That's the reason of the problem. NSIntegerMax
returns 9223372036854775807
on my 64-bit Mac and minPenalty
gets -1
value (since int
type cannot store such a big number).
将 NSIntegerMax
替换为 INT_MAX
。它应该返回正确的值: 2147483647
。这是 NSIntegerMax
根据答案的此问题。
Replace the NSIntegerMax
by INT_MAX
. It should return the correct value: 2147483647
. That's the number NSIntegerMax
returns on 32-bit machines according to the answer to this question.
运行应用程序, >
Run the app and you'll get your QR code!
这篇关于在Mac上使用ZXingObjC创建QR条形码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!