将dataURL从本地存储加载到HTML Canvas

时间:2015-12-15 12:35:32

标签: javascript html5 canvas

我在从本地存储中将dataURL加载到我的画布时遇到了一些麻烦。

           PrintDialog pDia = New PrintDialog()
           PrinterSettings ps = New PrinterSettings()

            pDia.Document = PrintDocument1
            pDia.Document.DocumentName = "Your File Name"

            ps.PrinterName = item.ToString()
            ps.PrintToFile = False

            //Create folder inside Bin folder to save PDFs
           String strReportBackupPath = "C:\\"

            String strFilePath  = strReportBackupPath & "\\" & pDia.Document.DocumentName & ".pdf"
            //To avoid the replace dialog of cutePDF - To save new file if have same name
            ps.PrintFileName = strFilePath 
            PrintDocument1.PrinterSettings = ps
            PrintDocument1.Print()

我设法将dataURL保存到本地存储中,当我在console.log中时,我可以查看它:

local storage which save the canvas in a dataURL

我设法使用此代码保存它:

localStorage.getItem(canvasArea)

但是当我尝试使用下面的代码放置dataURL时,它没有做任何事情。

document.getElementById("saveButton").addEventListener("click", function()
{  
   var canvas = document.getElementById("canvasArea"),
   ctx = canvas.getContext("2d");

   localStorage.setItem(canvasArea, canvas.toDataURL());
})

我错过了一些明显的东西还是我是傻瓜? 任何帮助,将不胜感激! 谢谢!

1 个答案:

答案 0 :(得分:0)

console.loglocalStorage.getItem(canvasArea),并确切了解它的内容。在我想要loadCanvas(""+ dataURL);而不是loadCanvas(dataURL);

之前,我有类似的奇怪问题