如何使用ipod前置摄像头扫描条码

发布于 2025-01-04 13:04:06 字数 2011 浏览 0 评论 0原文

我正在使用后置摄像头读取条形码数据...并且扫描效果很好。现在我想使用前置摄像头...我该怎么做?我应该在哪里更改?我使用了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];
                     }

I am using back camera to read bar code data...and it is scanning perfectly.Now I want to use front camera for this...How can I do this? Where should I make change?I have used ZBar bar code reader

my code is:

   - (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];
                     }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑疤怪 2025-01-11 13:04:06

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

  picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;

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

If I understand your question correctly, all you have to do is open your Camera to be in Front Mode instead of Rear Mode, so write this inside the method where you call the picker for the first time:

  picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;

Hope this answers your question. If not, tell me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文