简体   繁体   English

React Native 如何从图库中读取二维码

[英]React Native how can I read QR code from gallery

I have the functionality to Scan QR to view the profile of a person.我具有扫描 QR 以查看个人资料的功能。 Everything is working fine but I also want a functionality to decode/to read QR from my gallery instead of scanning it.一切正常,但我还想要一个功能来解码/从我的画廊读取 QR而不是扫描它。

So it would go like this.所以它会像这样 go 。

  1. Users can Scan QR to view profiles.用户可以扫描二维码查看个人资料。
  2. There's an option above that the user can import the QR code image from the gallery and once it's imported it will decode the image if its a correct QR or not.上面有一个选项,用户可以从图库中导入 QR 码图像,一旦导入,它将解码图像是否正确。
  3. If the QR is correct and it exists in DB then go to the user profile.如果 QR 正确且存在于 DB 中,则将 go 发送到用户配置文件。
  4. If not return an error saying either an invalid qr or user does not exist.如果不返回错误,说明 qr 无效或用户不存在。

I think Apps like LINE, WeChat have this functionality instead of scanning the QR they can just save the QR code into their library sent by their friend or another user then import that and decode it or read and then tadah.我认为像 LINE、微信这样的应用程序有这个功能,而不是扫描 QR,他们可以将 QR 码保存到他们的朋友或其他用户发送的库中,然后导入并解码或读取,然后 tadah。

What I had in mind is first I need a native library for reading my gallery.我的想法是首先我需要一个本地库来阅读我的画廊。 Once the user selected I need a library or functionality to read/decode the image if its a QR code or not.用户选择后,我需要一个库或功能来读取/解码图像(无论是否为 QR 码)。

How can I achieve this?我怎样才能做到这一点? I did some googling and research already but I haven't found an existing library for that.我已经进行了一些谷歌搜索和研究,但我还没有找到一个现有的图书馆。

Appreciate it if someone could help.如果有人可以提供帮助,我们将不胜感激。 Thanks谢谢

Use rn-qr-generator to decode a QR code in an image.使用rn-qr-generator解码图像中的二维码。

import RNQRGenerator from 'rn-qr-generator';

RNQRGenerator.detect({
  uri: PATH_TO_IMAGE, // local path of the image. Can be skipped if base64 is passed.
  base64: imageBase64String, // If uri is passed this option will be skipped.
})
  .then(response => {
    const { values } = response; // Array of detected QR code values. Empty if nothing found.
  })
  .catch(error => console.log('Cannot detect QR code in image', error));

It will return an array of detected QR codes' values Works well on iOS and Android platforms.它将返回一组检测到的二维码值在 iOS 和 Android 平台上运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM