我正在尝试使用http://github.com/TheLevelUp/ZXingObjC在我的苹果应用上创建二维码。
它适用于所有条形码类型,但在QRcode上返回nil!'result‘和'error’都为空。下面是我的代码:
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);
}上面有什么问题?
发布于 2013-06-18 02:31:37
我也有同样的问题。以下是解决此问题的方法。
ZXingObjC\qrcode\encoder\ZXEncoder.m
int minPenalty = NSIntegerMax;。它必须有一个警告:从'long‘到’‘的隐式转换会将9223372036854775807更改为-1。这就是问题的原因。在我的64位Mac机上,NSIntegerMax返回9223372036854775807,minPenalty返回-1值(因为int类型不能存储这么大的number).INT_MAX的类型不能存储这么大的值。它应该返回正确的值:2147483647。根据对应用程序this question.NSIntegerMax在32位机器上返回的数字,你会得到你的二维码!发布于 2013-04-17 09:06:42
尝试使用另一种方法,不是带有提示的这种方法,只使用:
[writer encode:@"yourmeganumber" format:kBarcodeFormatQRCode width:xxxx height:xxxx error:&error];
这对我很管用
试着让我知道
https://stackoverflow.com/questions/16024161
复制相似问题