-(void)decode:(CVImageBufferRef)BufferRef
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
CGImageRef videoFrameImage = [ZXCGImageLuminanceSource createImageFromBuffer:BufferRef];
CGImageRef rotatedImage = [self rotateImage:videoFrameImage degrees:0.0f];
[NSMakeCollectable(videoFrameImage) autorelease];
//Decoding:
ZXLuminanceSource* source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:rotatedImage] autorelease];
[NSMakeCollectable(rotatedImage) autorelease];
ZXBinaryBitmap* bitmap = [ZXBinaryBitmap binaryBitmapWithBinarizer:[ZXHybridBinarizer binarizerWithSource:source]];
NSError* error = nil;
// There are a number of hints we can give to the reader, including
// possible formats, allowed lengths, and the string encoding.
ZXDecodeHints* hints = [ZXDecodeHints hints];
ZXMultiFormatReader* reader = [ZXMultiFormatReader reader];
ZXResult* result = [reader decode:bitmap
hints:hints
error:&error];
if (result)
{
// The coded result as a string. The raw data can be accessed with
// result.rawBytes and result.length.
NSString* contents = result.text;
// The barcode format, such as a QR code or UPC-A
ZXBarcodeFormat format = result.barcodeFormat;
}
else
{
// Use error to determine why we didn't get a result, such as a barcode
// not being found, an invalid checksum, or a format inconsistency.
}
[pool drain];
}
答案 0 :(得分:1)
我遇到了这个问题,可以通过对相机生成的图像进行下采样来轻松解决。显然,图书馆处理条形码的资源太高了。通过在调用[image CGImage]之前将UIImage的大小减小到640x480,一切都运行良好。
答案 1 :(得分:0)
您已经评论过,您应该使用错误来确定未获得结果的原因,但实际上并没有这样做。看看error
中的内容。
答案 2 :(得分:0)