在IONIC中从图库解码QR码时出错

时间:2019-03-12 06:01:47

标签: typescript ionic-framework qr-code

我需要从Ionic画廊中解码QR图像。我正在使用以下代码从图库中获取图像并对其进行解码,

    gallery() { 

    let options = {
        destinationType: this.camera.DestinationType.FILE_URI,
        sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      };


      this.camera.getPicture(options).then((imageData) => {

        this.base64String = imageData;
        this.decodeImg((response) => {
          console.log("response:", response);
          if (response && response != "error in decoding QR Code" && response != "error decoding QR Code") {
            console.log(“Decoded Data ”, response);
          }
          else {
             console.log(“Error”);
          }
        });

      }, (err) => {
        console.log(“Error”, err);
      });
} 

    decodeImg(callback) {
    this.decodeImageFromBase64( this.base64String, (decodedInformation) => {
    console.log("Final Output  ", decodedInformation); 
    callback(decodedInformation);
  });

}


    decodeImageFromBase64(data, callback) {
    try {
      // set callback
      qrcode.callback = callback;
      // Start decoding
      qrcode.decode(data);

      } catch (error) {
      console.log("error  ", error); 
    }
    }

问题是,某些QR被正确解码,而对于某些QR,我收到“解码QR码时出错”。但是相同的QR在在线解码器中也可以正常工作。请让我知道,为什么某些QR无法正确解码的解决方案。

另外,还有什么方法可以从离子图像中解码图库中的QR图像。

0 个答案:

没有答案