Scaning static UIImage using ios ZBar SDK

前端 未结 2 1207
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 19:32

I want to scan a static UIImage using Zbar sdk, it gives error i.e. ZBarSymbol is Null

I also checked

ZBarReaderController: UIImagePickerCon

相关标签:
2条回答
  • 2020-12-21 20:00

    A stripped-down generic version of Baig's wonderful solution. Change ZBAR_I25 to desired code format.

    - (NSString *)findQRCode:(UIImage *)inputUIImage
    {
    
        ZBarReaderController *imageReader = [ZBarReaderController new];
    
        [imageReader.scanner setSymbology: ZBAR_I25
                                   config: ZBAR_CFG_ENABLE
                                       to: 0];
    
        id <NSFastEnumeration> results = [imageReader scanImage:inputUIImage.CGImage];
    
        ZBarSymbol *sym = nil;
        for(sym in results) {
            break;
        } // Get only last symbol
    
        if (!sym) {
            NSLog(@"No barcode found");
            return nil;
        }
    
        NSLog(@"Found barcode! quality: %d string: %@", sym.quality, sym.data);
        return sym.data;
    }
    
    0 讨论(0)
  • 2020-12-21 20:06

    Got solution:

    - (NSString *)scanForQR:(UIImage *)image
    {
    
        ZBarReaderController *imageReader = [ZBarReaderController new];
    
        [imageReader.scanner setSymbology: ZBAR_I25
                                   config: ZBAR_CFG_ENABLE
                                       to: 0];
    
        id <NSFastEnumeration> results = [imageReader scanImage:image.CGImage];
    
        ZBarSymbol *sym = nil;
        for(sym in results) {
            break;
        } // Get only last symbol
    
        if (!sym) {
            NSLog(@"No barcode found");
            return nil;
        }
    
        NSLog(@"Found barcode! quality: %d string: %@", sym.quality, sym.data);
        return sym.data;
    }
    
    0 讨论(0)
提交回复
热议问题