如何在ipod中使用前置摄像头进行条码扫描

时间:2012-02-11 05:03:57

标签: iphone objective-c camera ipod barcode-scanner

我正在使用后置摄像头读取条形码数据...它正在完美扫描。现在我想使用前置摄像头......我该怎么做?我应该在哪里进行更改?我使用过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 个答案:

答案 0 :(得分:9)

如果我理解你的问题,你所要做的就是打开你的相机而不是后方模式,所以在第一次调用选择器的方法中写下这个:

  picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;

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