简体   繁体   中英

image.src = canvas.toDataURL(“image/png”); Saving issue

How to save image.src = canvas.toDataURL("image/png"); in within the camera div onclick camera result automatically getting saved in the first image src line.

Working Codepen

You are editing the first img tag. But you need to edit the second one.

Change let image = document.querySelector("img"); to let image = document.getElementById("result");

and

Change <img src="" alt="" class="image image--hidden" /> to <img src="" id="result" alt="" class="image image--hidden" />

If I understand correctly, you want to download the image on click . To achieve this you should use an <a /> tag. Try the following:

function save(){

    let a = document.createElement('a');

    a.download = '';

    a.href = canvas.toDataURL("image/png");

    a.click();
}

Now you can use the save function whenever you want, even onclick .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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