我有一个svg图像,我想导出为png。如何解码由window.btoa使用Java编码的base64图像
在客户端使用JavaScript,我转换成的base64
var s = new XMLSerializer().serializeToString(document.getElementById("svg"))
var encodedData = window.btoa(s);
在服务器端我想将它解码,并创建一个.png文件
BASE64Decoder decoder = new BASE64Decoder();
byte[] imageByte = decoder.decodeBuffer(string);
但是,这给了我一个文件无法打开。
或者是否有任何其他方式可以将svg导出为png。因为我的SVG包含来自外部源的图像,我不能使用toDataUrl
对不起,我不知道如何通过SVG作为多/表单数据转换成PNG。它应该转换成PNG然后发送? – Jerry
该文件格式不重要。这个答案包含一些关于如何在java中进行文件上传的说明http://stackoverflow.com/questions/19510656/how-to-upload-files-on-server-folder-using-jsp –
感谢您的回复。我正在使用d3.js绘制svg,我想将它保存为png图像。因为我在svg中使用外部图像源,所以当我尝试使用** toDataUrl **时,出现CORS错误。您提供的参考不会帮助我:( – Jerry