【问题标题】:barcode scanner along with cordova camera preview条码扫描器以及科尔多瓦相机预览
【发布时间】:2019-03-01 14:50:07
【问题描述】:

如何将 phonegap 条形码扫描仪插件与 cordova-plugin-camera-preview 一起使用,这样当我在我的 Angular 应用程序中单击扫描按钮时,相机会在我的应用程序中预览并扫描条形码并给我结果

【问题讨论】:

  • 请包含一些您已经尝试过的代码示例。

标签: angular cordova camera barcode-scanner


【解决方案1】:

你让自己变得复杂

条码扫描插件

https://github.com/phonegap/phonegap-plugin-barcodescanner

上面提到的条形码扫描仪已经可以访问相机,您不必使用其他插件,例如您提到的用于 cordova 的相机预览插件

例子:

//plugin options
var options= {
      preferFrontCamera : true, // iOS and Android
      showFlipCameraButton : true, // iOS and Android
      showTorchButton : true, // iOS and Android
      torchOn: true, // Android, launch with the torch switched on (if available)
      saveHistory: true, // Android, save scan history (default false)
      prompt : "Place a barcode inside the scan area", // Android
      resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
      formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
      orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
      disableAnimations : true, // iOS
      disableSuccessBeep: false // iOS and Android
  }

 //success callback
function onSuccess(result) {
      alert("We got a barcode\n" +
            "Result: " + result.text + "\n" +
            "Format: " + result.format + "\n" +
            "Cancelled: " + result.cancelled);
 }

//error callback
function onError(error) {
      alert("Scanning failed: " + error);
}

cordova.plugins.barcodeScanner.scan(onSuccess, onError, options); 

【讨论】:

  • 但这将单独打开相机应用程序,而不是在我的应用程序的容器内......就像所有移动应用程序必须扫描二维码而不打开另一个相机应用程序一样
  • 话虽如此,我可以保证你不能使用这个插件来做到这一点,这个插件只有 3 个参数,没有办法在上面传递 base64 图像或任何东西
  • stackoverflow.com/questions/31315320/… 根据这个答案,相机可以在 div 内打开。我只想连接这两个,即当我点击扫描时触发此相机预览而不是我的手机的本地相机跨度>
  • 是的,您可以在应用程序中打开相机,但条形码扫描仪插件支持图像作为输入这一事实,它只能从自己的相机功能中获取图像
  • 你需要一个以图片为参数的条形码插件
猜你喜欢
  • 1970-01-01
  • 2018-11-09
  • 2018-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-05
  • 1970-01-01
相关资源
最近更新 更多