How to get the type of code from zbar?

2019-06-25 03:57发布

In my Application Zbar is decoding perfectly. But the problem is Zbar can decode both QR code and Bar code . So after decoding How do i get the type of Encoding Style ?

thanks in advance

2条回答
孤傲高冷的网名
2楼-- · 2019-06-25 04:36

There are return codes for type in ZBarSymbol. You will be looking for ZBAR_QRCODE for QR codes

ZBarSymbol documentation

Something like this should help you to get the symbol out:

- (void) readerView: (ZBarReaderView*) view didReadSymbols: (ZBarSymbolSet*) syms  fromImage: (UIImage*) img 
{
    //do something useful with results and display resultText in resultViewController
    for(ZBarSymbol *sym in syms) 
    {
        imageResult3.image = img; 
        resultText.text = sym.typeName;
        resultText.text =  [ resultText.text stringByAppendingString:@" - " ];
        resultText.text =  [ resultText.text stringByAppendingString:sym.data ]; 

    }
}
查看更多
爷的心禁止访问
3楼-- · 2019-06-25 04:47

What i did was,

- (void) imagePickerController: (UIImagePickerController*) reader  didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
    ZBarImage *zImage = [[ZBarImage alloc] initWithCGImage:image.CGImage];
    ZBarImageScanner *scanner = [[ZBarImageScanner alloc] init];
    [scanner setSymbology: ZBAR_I25
                        config: ZBAR_CFG_ENABLE
                        to: 0];
    [scanner scanImage:zImage];
    ZBarSymbolSet *set = [scanner results];

    ZBarSymbol *symbol = nil;
    for (symbol in set)
        break;
    codeType.text = symbol.typeName
}
查看更多
登录 后发表回答