I am drawing an image onto canvas. Then I want to save the image. I tried canvas.toDataURL("image/png"), but I realized that I can't use toDataURL() because of security reason. However, I have to save the image. How can I save the image?
This is my sample source code.
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();
}
}