首页 > 解决方案 > 离子框架(角度) - 如何解码二维码图像?

问题描述

我正在使用离子框架 v3。我正在尝试解码从图库中选择的二维码图像。

我尝试使用链接,但它大多不解码。

我做了链接:

 const codeReader = new BrowserQRCodeReader();
    codeReader.decodeFromImage(undefined, imgData).then((result: any) => {
      console.log(result); 
    }).catch((err:any) => {
     console.log(err);
    });

我正在传递 base64 图像数据。

谁能建议从画廊解码图像的最佳方法?

标签: ionic-frameworkionic3angular5qr-code

解决方案


您不能直接通过该decodeFromImage方法使用 base64 数据,但需要提供图像的 URL。如何获取 URL 取决于您用于让用户选择图像的插件。

如果您只有 base64 数据,则可以改为img在页面中添加一个隐藏元素并使用 base64 数据作为其src属性。然后decodeFromImage()将此img元素用作第一个参数。


推荐阅读