如何使用canvas.toDataURL()将我的画布保存为图像: 这是我的代码:
var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
window.location.href=image;
工作正常。如何更改下载文件的名称?它刚刚下载"下载"并且没有延期。我如何将本画布保存为本地的png图像。请指导我
答案 0 :(得分:1)
a
元素。href
属性设置为您的网址。download
属性设置为所需的文件名。click
事件。或者只看this answer here。
答案 1 :(得分:0)
您可以查看codepen上的演示Click to Take a Screenshot & Download it!并阅读canvas2image.js源代码来处理您的问题,或者只需使用canvas2image.js
来完成您的功能。
你可以像这样使用它, filename是可选的,默认为Date.now():
Canvas2Image.saveAsImage(canvasObj, width, height, type, fileName)
Canvas2Image.saveAsPNG(canvasObj, width, height, fileName)
Canvas2Image.saveAsJPEG(canvasObj, width, height, fileName)
Canvas2Image.saveAsGIF(canvasObj, width, height, fileName)
Canvas2Image.saveAsBMP(canvasObj, width, height, fileName)
Canvas2Image.convertToImage(canvasObj, width, height, type)
Canvas2Image.convertToPNG(canvasObj, width, height)
Canvas2Image.convertToJPEG(canvasObj, width, height)
Canvas2Image.convertToGIF(canvasObj, width, height)
Canvas2Image.convertToBMP(canvasObj, width, height)