简体   繁体   English

如果在手机上是二进制的,如何获取图像src

[英]how to get image src if it is in binary on mobile phones

i am creating qr codes using This Libary and this is how it works, it creates an image tag and stores the qr code image in the src as a binary image.我正在使用这个库创建二维码,这就是它的工作原理,它创建一个图像标签并将二维码图像作为二进制图像存储在 src 中。 i want to download the qr code image, it works perfectly on my laptop but when i tested it on my mobile phone it didn't work, i even tried to alert the src of the image but it came out empty, how can i solve this?我想下载二维码图像,它在我的笔记本电脑上完美运行,但是当我在我的手机上测试它时它不起作用,我什至试图提醒图像的 src 但它出来是空的,我该如何解决这个? here is my code:这是我的代码:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>qrcode</title>

  <style>
    #qrcode {
      width: 160px;
      height: 160px;
      margin-top: 15px;
    }
  </style>
</head>

<body>
  <input type="button" id="cmd" value="Save PNG" onclick="saveimg()" />
  <a href="" download="ConferPressQrTicket" id="download">download</a>

  <div id="qrcode"></div>
  <script src="./qrcode.min.js"></script>

  <script type="text/javascript">
    // var qrcode = new QRCode("qrcode");
    var qrcode = new QRCode("qrcode", {
    text: "",
    width: 200,
    height: 200,
    colorDark : "#000",
    colorLight : "#ffffff",
    correctLevel : QRCode.CorrectLevel.H
});

    function makeCode() {
      let TickectId = location.href.split("=")[1];
      let dfd = qrcode.makeCode("TickectId")

    }

    function saveimg() {
      alert(document.getElementsByTagName("img")[0].src)
      document.getElementById("download").href = document.getElementsByTagName("img")[0].src;
    }
    makeCode();
    document.getElementById("cmd").addEventListener("click", () => {
      alert(document.getElementsByTagName("img")[0].src)
      document.getElementById("download").href = document.getElementsByTagName("img")[0].src;
    })

  </script>
</body>

</html>

add this to your code将此添加到您的代码中

var can = document.querySelector("#qrcode canvas");
alert(can.toDataURL())
document.getElementById("download").href = can.toDataURL();

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

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