代碼如下:var img = new Image; img.crossOrigin = "Anonymous" ;//不加此行代碼報(bào)Tainted canvases may not be exported.加了報(bào)Image from origin 'file://' has been blocked from loading by Cross-Origin Resource Sharing policy: Invalid response. Origin 'null' is therefore not allowed access.img.src = 'imgs/1.png'; img.onload = function () {var canvas = document.createElement("canvas");canvas.width = img.width;canvas.height = img.height;var ctx = canvas.getContext("2d");ctx.drawImage(img, 0, 0, img.width, img.height);ctx.fillStyle = '#000'; // 文字填充顏色 ctx.font = '13px Adobe Ming Std'; ctx.fillText('怎么得到你想要的?',10,20); var ext = img.src.substring(img.src.lastIndexOf(".")+1).toLowerCase();var dataURL = canvas.toDataURL("image/"+ext);console.log(dataURL) }請(qǐng)問該怎么解決?
用canvas處理圖片后使用toDataURL方法報(bào)錯(cuò)是什么原因?
一只名叫tom的貓
2018-12-20 18:15:28