angularjs Ionic 6上的自定义条形码实时扫描仪

3qpi33ja  于 2023-03-07  发布在  Angular
关注(0)|答案(1)|浏览(175)

我正在用Angular开发一个应用程序,我试图将相机预览插件与能够真实的识别条形码的js库结合起来。不幸的是,在尝试一些库时,产量并不是理想的(在10个条形码中,只返回1)。我已经尝试了QuaggaJS和Zxing库,但它们在iOS设备上显示问题。以前有人遇到过这样的情况吗?我如何将相机预览定制与Ionic 6中的实时条形码阅读相结合?非常感谢。
我试过ZXing和QuaggaJS这样的库,但它们在iOS和Android设备上不兼容或太慢。

qvtsj1bj

qvtsj1bj1#

你可以尝试这个插件为您的相机功能?
https://capacitorjs.com/docs/apis/camera
安装插件:
npm install @capacitor/camera
npx cap sync
示例代码:

import { Camera, CameraResultType } from '@capacitor/camera';

const takePicture = async () => {
  const image = await Camera.getPhoto({
    quality: 90,
    allowEditing: true,
    resultType: CameraResultType.Uri
  });

  // image.webPath will contain a path that can be set as an image src.
  // You can access the original file using image.path, which can be
  // passed to the Filesystem API to read the raw data of the image,
  // if desired (or pass resultType: CameraResultType.Base64 to getPhoto)
  var imageUrl = image.webPath;

  // Can be set to the src of an image now
  imageElement.src = imageUrl;
};

相关问题