我有如下画布代码:
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var imageObj = new Image();
imageObj.src = 'images/floor1.jpg';
imageObj.onload = function() {
context.drawImage(imageObj, 0, 0, 610, 290, 0, 0, 610, 290);
context.beginPath();
context.rect(62, 66, 66, 25); /* rectangle F sold */
context.rect(221, 66, 66, 25);
context.rect(327, 66, 66, 25);
context.rect(488, 66, 66, 25);
context.rect(62, 181, 66, 25);
context.rect(186, 181, 66, 25);
context.rect(363, 181, 66, 25);
context.rect(488, 181, 66, 25);
context.lineWidth = 2;
context.strokeStyle = 'black';
context.stroke();
var dataURL = canvas.toDataURL("image/png");
document.getElementById('out').src = dataURL;
};
但这在 IE8 中不起作用。我尝试添加 explorercanvas 代码:
< script src="excanvas.js"></script >
if (typeof(G_vmlCanvasManager) != 'undefined') {
myCanvas = G_vmlCanvasManager.initElement(myCanvas);
}
但这不起作用。有任何想法吗?