简体   繁体   English

从图像ZBar扫描条形码

[英]Scan Barcode from image ZBar

I scan any barcode by using zbar at that time this API scans a barcode also It scans an image. 我当时使用zbar扫描任何条形码,该API也会扫描条形码。它还会扫描图像。 any one please help me to do this...assume that I have one Mazza Bottle in that bottle Barcode is there But particular barcode is on Orange plastic. 任何人都可以帮助我做到这一点...假设我的瓶子里有一个Mazza瓶,上面有条形码,但是橙色塑料上有特定的条形码。 Ween ever I scan any barcode image at that time zbar scans barcode with orange color... So I just want to nget barcode not any other portion than barcode. 那时我扫描任何条形码图像时,zbar都会扫描橙色的条形码...因此,我只想获取条形码,而不是条形码。

- (void)viewDidLoad
{
   [super viewDidLoad];
   reader = [ZBarReaderViewController new];
   capture = [ZBarCaptureReader new];
   capture.captureDelegate = self;
   reader.readerDelegate = self;
   reader.supportedOrientationsMask = ZBarOrientationMaskAll;
   ZBarImageScanner *scanner = reader.scanner;

    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;

    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;
    label.text = symbol.data;
    imageView.image = [info objectForKey: UIImagePickerControllerOriginalImage];

    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissViewControllerAnimated:YES completion:^{}];

}

zbar doesnt retouch the image for you. zbar不会为您修饰图像。 it gives you the image it scanned without modification. 它为您提供扫描后的图像而无需修改。

you can get the cropped image (the one in the rectangle of the scanner view) 您可以获取裁剪后的图像(扫描仪视图矩形框中的一个)

- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *img = info[UIImagePickerControllerOriginalImage];
    ZBarImage *cropped = [[ZBarImage alloc] initWithCGImage:img.CGImage crop:((ZBarReaderViewController*)imagePicker).scanCrop size:img.size];
    //...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM