ionic-framework - 离子框架(角度) - 如何解码二维码图像?
问题描述
我正在使用离子框架 v3。我正在尝试解码从图库中选择的二维码图像。
我尝试使用链接,但它大多不解码。
我做了链接:
const codeReader = new BrowserQRCodeReader();
codeReader.decodeFromImage(undefined, imgData).then((result: any) => {
console.log(result);
}).catch((err:any) => {
console.log(err);
});
我正在传递 base64 图像数据。
谁能建议从画廊解码图像的最佳方法?
解决方案
您不能直接通过该decodeFromImage
方法使用 base64 数据,但需要提供图像的 URL。如何获取 URL 取决于您用于让用户选择图像的插件。
如果您只有 base64 数据,则可以改为img
在页面中添加一个隐藏元素并使用 base64 数据作为其src
属性。然后decodeFromImage()
将此img
元素用作第一个参数。
推荐阅读
- android - Android RecyclerView - 父视图窃取具有负越界放置的网格项的子项的触摸事件
- c# - NLog 数据库目标不适用于已识别的 Stackify 目标
- python - Django - 如何为models.DateField()设置日期格式?终端不断抛出日期验证错误
- powershell - Powershell:在 Win 10 上查找所有已安装的应用程序
- python - 如何抓取具有嵌套表的表?
- dji-sdk - Gimbal Rotation - 在旋转完成之前触发 withCompletion 方法
- python - 递归查找列表列表中的最小值
- swift - 在 ForEach 迭代中将数据传递到自定义视图 (SwiftUI)
- c# - HttpWebRequest StreamReader 失败,出现 utf-8 is not a supported encoding name 错误
- java - 未显示覆盖私有方法错误