2

您好我已經設法使excanvas在IE8工作了簡單的例子,但我不能讓包含在IE8的drawImage以下工作的帆布例子。有沒有人有excanvas和drawImage方法的經驗。 感謝您的幫助......excanvas drawImage方法不起作用在IE8

var foo = document.getElementById("foo"); 
var canvas = document.createElement('canvas');` 

canvas.setAttribute("width", 300);
canvas.setAttribute("height", 300);
foo.appendChild(canvas);
canvas= G_vmlCanvasManager.initElement(canvas);
var ctx = canvas.getContext('2d');
ctx.save();
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.translate(canvas.width/2 , canvas.height/2);
ctx.drawImage(image, -165, -160);
ctx.rotate(100 * Math.PI/180);
ctx.drawImage(image2, -13, -121.5);
ctx.restore();

image1.src = 'img.png'; 
image2.src = 'img2.png'; 
+0

是否在瀏覽器的原生帆布工作?也許你不等待你的圖片加載? – apsillers 2013-04-04 16:12:30

+0

我有另一個版本,其中工程剛纔我在這裏改變變量foo和創建一個canvas元素。 – user1874941 2013-04-04 16:14:34

回答

1

使用測試案例隔離的drawImage:

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title>Overflow Test</title> 
 
<style> 
 
body { 
 
    text-align: center 
 
} 
 
</style> 
 
<!--[if IE]><script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/excanvas.js"></script><![endif]--> 
 
<script> 
 
window.onload = function() { 
 
    var ctx = document.getElementById('c').getContext('2d'); 
 
    var img = document.images[0]; 
 
    ctx.rotate(Math.PI/8); 
 
    ctx.drawImage(img, 50, 50); 
 
    img.style.display = 'none'; 
 
}; 
 
</script> 
 
</head> 
 
<body> 
 

 
<img src="http://opera.com/favicon.ico"> 
 

 
<canvas id="c" width="200" height="200"></canvas> 
 

 
</body> 
 
</html>

參考

Explorer Canvas test cases: drawimage.html