2012-02-11 80 views
6

我正在使用后置摄像头来读取条码数据......并且它正在完美扫描。现在我想使用前置摄像头进行此操作...我该怎么做? ?我应该在哪里做出改变我已经使用zbar和条形码阅读器如何在ipod中使用前置摄像头进行条码扫描

我的代码是:

- (IBAction) scanButtonTapped 
      { 
     // 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; 
          bid.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]; 
        } 
+0

任何人都可以帮助我吗? – 2012-02-11 07:24:33

回答

8

如果我正确理解你的问题,你所要做的就是打开你的相机是在前方模式,而不是因此,在第一次拨打选取器的方法中写下此内容:

picker.cameraDevice=UIImagePickerControllerCameraDeviceFront; 

希望这能回答你的问题。如果没有,告诉我。

+0

是啊...它正在工作......非常感谢您的善意帮助..... – 2012-02-13 04:49:07

+3

这工作可靠吗?前置摄像头不支持自动对焦,这就是为什么我问。我正在使用内置的ios支持[AVCaptureMetadataOutput](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureMetadataOutput/Reference/Reference.html#//apple_ref/occ/cl/AVCaptureMetadataOutput)扫描条形码,我发现前置摄像头不是很可靠。 – 2014-04-25 04:26:24

相关问题