2012-03-19 75 views
1

此問題只發生在Chrome 18Dev +。版本17中。 應該是模式的區域充滿了黑色。在Chrome 18Dev +中。 Html5 canvas'cre​​atePattern'無法正確繪製圖像

下面的代碼,你可以將它複製並在Chrome中運行它:

<!DOCTYPE HTML> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>clock</title> 
    <style type="text/css"> 
     canvas{ 
      display:block; 
      width:400px; 
      height:400px; 
      border:2px solid #000; 
      margin:100px auto; 
     } 
    </style> 
</head> 
<body> 
    <canvas id='c'></canvas> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
     var pic = new Image(); 
     $(function(){ 
      $(pic).load(function() { 
       var canvas = document.getElementById('c'); 
       canvas.width = 400; 
       canvas.height = 400; 

       if (canvas.getContext) { 
        var ctx = canvas.getContext('2d'); 

        ctx.fillStyle = ctx.createPattern(pic, 'repeat'); 


        setInterval(function() { 
         ctx.clearRect(0, 0, canvas.width, canvas.height); 
         ctx.arc(canvas.width*0.5, canvas.height*0.5, 165, 0, Math.PI*2, false); 
         ctx.fill(); 
        }, 1000); 
       } 
      }); 
     }); 
     pic.src = 'https://www.google.com.hk/images/nav_logo105.png'; 
    </script> 
</body> 

回答

0

哦,我知道這一點。

I reported it back in January, its still broken in Chrome Dev。看到最後的評論。

事實證明,該模式將在第一次繪製在標籤中。然後你必須關閉該選項卡併爲其重新創建一個新的。刷新頁面不會這樣做。這是一個真正的痛苦。