简体   繁体   中英

How download base64 data as image?

我使用 vue-signature 库,但不知道如何下载生成为图像的 base64 数据,这是库的链接: https : //www.npmjs.com/package/vue-signature我已经阅读了文档和看到 "Save()" 方法将图像另存为 PNG/JPG ......但它给了我 base64 数据,谢谢你的合作,我用的是 vue js

This is not the most optimized solution, But it works.

var a = document.createElement("a"); //Create <a>
a.href = "data:image/png;base64," + ImageBase64; //Image Base64 Goes here
a.download = "Image.png"; //File name Here
a.click(); //Downloaded file

In your case you can try this

var canvas = document.querySelector("canvas");

var signaturePad = new SignaturePad(canvas);

// Returns signature image as data URL (see https://mdn.io/todataurl for the list of possible parameters)
signaturePad.toDataURL("image/jpeg"); // save image as JPEG

source : https://vuejsexamples.com/vue-signature-pad-component/

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