我正在画布上绘制图像。然后我想保存图像。我尝试了 canvas.toDataURL("image/png"),但我意识到由于安全原因我不能使用 toDataURL()。但是,我必须保存图像。如何保存图像?
这是我的示例源代码。
window.onload = function(){
var oCanvas = document.getElementById("work_pallet");
var oContext = oCanvas.getContext("2d");
var imageObj = new Image();
imageObj.onload = function() {
oContext.drawImage(imageObj, 0, 0, oCanvas.width, oCanvas.height);
}
imageObj.src = "http://www.ehanftp.co.kr/ueditor/data/20130204/mini2/guide.pdf_1.png";
function saveImage(){
var bRes = false;
alert(oCanvas.toDataURL());
bRes = Canvas2Image.saveAsPNG(oCanvas);
if (!bRes) {
alert("Sorry, this browser is not capable of saving image!");
return false;
}
}
document.getElementById("saveCanvasImage").onclick = function() {
saveImage();
}
}