如何在iPod上使用前置摄像头进行条形码扫描

7

我正在使用后置摄像头读取条形码数据...扫描效果很好。现在我想使用前置摄像头进行读取...该怎么做?我应该在哪里修改代码?我使用的是ZBar条形码阅读器。

我的代码如下:

   - (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];
                     }
1个回答

9
如果我理解您的问题正确,您所要做的就是打开相机并进入前置模式而非后置模式。因此,请在第一次调用选择器的方法中添加以下代码:
  picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;

希望这个回答能解决你的问题。如果不能,请告诉我。

4
这是否可靠?前置摄像头不支持自动对焦,这就是我问的原因。我正在使用内置的iOS支持,使用AVCaptureMetadataOutput扫描条形码,但我发现前置摄像头不太可靠。 - Sandeep Phadke

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接