|
二维码生成自己处理好,然后就可以了
- function BrowseFolder() {
- var img = document.getElementById("testImg").src;
- //console.log(img);
- img=img.replace("data:image/png;base64,","")
- //return false;
- var eventPayload ={
- "content": img,
- //图片base64格式太多,此处省略。不包含前缀:data:image/png;base64,
- "fileName": "分享.png",
- "imageType": "png"
- };
-
- console.log(eventPayload)
- var content=eventPayload.content;
- var imageType=eventPayload.imageType;
- var fileName=eventPayload.fileName;
- console.log('fileName');
- if(content){ // 接口返回的数据部分
- // 解析图片
- // 因接口直接返回了base64代码部分,所以不需要截取,如果含"data:image/png;base64," 则需要自己做截取处理
- var raw = window.atob(content);
- var rawLength = raw.length;
- var uInt8Array = new Uint8Array(rawLength);
- for(var i = 0; i < rawLength; ++i) {
- uInt8Array[i] = raw.charCodeAt(i);
- }
- var blob = new Blob([uInt8Array], {type:'image/'+imageType});
- //保存图片
- var aLink = document.createElement('a');
- var evt = document.createEvent("HTMLEvents");
- evt.initEvent("click", true, true);
- aLink.download = fileName;
- aLink.href = URL.createObjectURL(blob);
- aLink.click();
- } else{
- console.log('没有base64代码');
- }
- }
复制代码 |
|