【问题标题】:Use camera scan QRCode or BarCode in ObjectiveC在 Objective C 中使用相机扫描二维码或条形码
【发布时间】:2012-07-25 08:39:44
【问题描述】:

我想构建一个应用程序来扫描 QRCode 和 Barcode。我想使用相机扫描图像包含代码(QRCode 或 BarCode)但不拍照。现在我不知道这样做。
任何人,请提供一些参考!

【问题讨论】:

    标签: objective-c qr-code barcode-scanner


    【解决方案1】:

    你应该看看:http://zbar.sourceforge.net/

    【讨论】:

      【解决方案2】:

      下载 ZBarSDK 并将其导入 pch 文件,然后使用此代码

      // BarCodeView.h
      @interface BarCodeView : UIViewController  < ZBarReaderDelegate > {
      UIImageView *resultImage;
      UITextView *resultText;
        }
      @property (nonatomic, retain) IBOutlet UIImageView *resultImage;
      @property (nonatomic, retain) IBOutlet UITextView *resultText;
      - (IBAction) scanButtonTapped;
      
          // BarCodeView.m
        @synthesize resultImage, resultText;
         - (IBAction) scanButtonTapped
       {
      NSLog(@"TBD: scan barcode here...");
      // ADD: present a barcode reader that scans from the camera feed
      ZBarReaderViewController *reader = [ZBarReaderViewController new];
      reader.readerDelegate = self;
      reader.supportedOrientationsMask = ZBarOrientationMaskAll;
      
      ZBarImageScanner *scanner = reader.scanner;
      // TODO: (optional) additional reader configuration here
      
      // EXAMPLE: disable rarely used I2/5 to improve performance
      [scanner setSymbology: ZBAR_I25
                     config: ZBAR_CFG_ENABLE
                         to: 0];
      
      // present and release the controller
      [self presentModalViewController: reader
                              animated: YES];
      [reader release];
        }
       - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
        {
      // ADD: get the decode results
      id<NSFastEnumeration> results =
      [info objectForKey: ZBarReaderControllerResults];
      ZBarSymbol *symbol = nil;
      for(symbol in results)
          // EXAMPLE: just grab the first barcode
          break;
      
      // EXAMPLE: do something useful with the barcode data
      resultText.text = symbol.data;
      
      // EXAMPLE: do something useful with the barcode image
      resultImage.image =
      [info objectForKey: UIImagePickerControllerOriginalImage];
      
      // ADD: dismiss the controller (NB dismiss from the *reader*!)
      [reader dismissModalViewControllerAnimated: YES];
       }
      

      【讨论】:

        【解决方案3】:

        两个最活跃的项目是ZBarZXing

        你没有提到你的目标是 iOS 还是 OS X。我不相信 ZBar 支持 OS X。ZXing 支持。我相信 ZBar 对一维代码的支持比 ZXing 基于 C++ 的端口更好。

        (FWIW,我是 ZXing 的 C++/OS X/iOS 端口的积极贡献者。)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-04-25
          • 2020-01-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-04-07
          • 2021-11-30
          相关资源
          最近更新 更多