将Base64的字符串转换为二进制数,代码如下:
function dataURItoBlob(dataURI) { // convert base64 to raw binary data held in a string // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this var byteString = atob(dataURI.split(',')[1]); // separate out the mime component var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0] // write the bytes of the string to an ArrayBuffer var ab = new ArrayBuffer(byteString.length); // create a view into the buffer var ia = new Uint8Array(ab); // set the bytes of the buffer to the correct values for (var i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } // write the ArrayBuffer to a blob, and you're done var blob = new Blob([ab], {type: mimeString}); return blob; } // 将Base64的字符串转换为二进制数据 var blob = dataURItoBlob(image); // 使用FileSaver.js的saveAs函数进行下载 saveAs(blob, "images.png");
网友回复
python+Quill如何实现多人实时文档编辑html?
什么是ai的6A工作流规则?
&、nohup、screen、tmux在linux中后台执行的区别?
python如何将调用ai大模型生成的文件修改行操作指令修改原文件后保存?
python如何将2d平面线图转换成数字2d线稿图?
acejs代码编辑器如何调用openai api实现选择代码修改与代码自动补全?
ace.js如何获取选择文本的开始和结束行数?
如何把qwen code cli或gemini cli的免费调用额度换成http api对外开放接口?
如何限制windows10电脑只能打开指定的程序?
python如何调用ai大模型实现web网页系统的功能测试并生成测试报告?