简体   繁体   English

使用javascript将Base64转换为图像文件

[英]Convert Base64 to image file with javascript

Does anyone know of any simple javascript that I can use to turn a base64 string into an image (jpg format preferably), so that I can save the image to a file? 有谁知道我可以用来将base64字符串转换为图像(最好是jpg格式)以便将图像保存到文件中的任何简单的javascript吗? This is for a signature pad application. 这用于签名板应用程序。 I can get the signature into a base64 format, but need to save the signature as an image file to use for embedding into a Crystal Report. 我可以将签名转换为base64格式,但是需要将签名另存为图像文件,以用于嵌入到Crystal Report中。

I have tried this method in a JSP page to print the image from a base64 string, I guess this should hold good for javascript too. 我已经在JSP页面中尝试过此方法以从base64字符串打印图像,我想这也应该适合javascript。 Do not have sample data for now to verify, but here's how I would try it. 目前没有样本数据可进行验证,但是这是我尝试的方法。

var oImg=document.createElement("img");
var baseString = null;    //the base64 string you have
var imsc = 'data:image/jpg;base64, '+baseString;
oImg.setAttribute('src', imsc);
document.body.appendChild(oImg);

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

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