2012-02-11 57 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

相關問題