[問題] 關於canvas的存檔問題

看板Web_Design作者 (12345)時間14年前 (2011/08/14 04:53), 編輯推噓1(105)
留言6則, 3人參與, 最新討論串1/1
最近想用canvas做一個圖片與文字編輯的功能,但卻碰到一些問題 我想用canvas先畫一張圖檔(ex. picture.png) 之後在canvas上加一些文字(ex. Hello World) 然後再用toDataURL將canvas上的東西儲存起來 不過開啟的canvas圖檔上卻沒有picture.png的圖 只有Hello World的文字 請問是那裡出了問題了呢? 我的code如下,感謝解答 <HTML> <BODY> <canvas id="screen" width="570" height="395"></canvas> <script type="text/javascript"> function draw(){ var ctx = document.getElementById('screen').getContext('2d'); var img = new Image(); img.onload = function(){ ctx.drawImage(img,1,1); } img.src = 'http://www.google.com/intl/en_com/images/srpr/logo3w.png'; ctx.fillText("Hello, World!", 1, 200); } draw(); window.open(document.getElementById('screen').toDataURL()); </script> </BODY> </HTML> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 129.2.166.105 ※ 編輯: laihuei 來自: 129.2.166.105 (08/14 04:57)

08/14 06:33, , 1F

08/14 06:35, , 2F
1.你的 img.src 如果直接用非自己網域的會失敗
08/14 06:35, 2F

08/14 06:35, , 3F
2. 你的圖片來不及 onload ,你的程式就跳視窗了
08/14 06:35, 3F

08/14 07:15, , 4F
感謝解答:)
08/14 07:15, 4F

08/14 17:23, , 5F
:D 嘿冇啥啦
08/14 17:23, 5F

08/14 20:56, , 6F
隨機圖片
08/14 20:56, 6F
文章代碼(AID): #1EHkHbfo (Web_Design)