[英]Drawing image on the canvas using excanvas
我正在使用excanvas.js庫在IE(9以下)瀏覽器中支持畫布功能。 我目前面臨的問題是,excanvas期望image作為drawImage()方法的第一個參數。 我發現它不支持其他畫布或視頻作為第一個參數。 實現此功能的解決方法是什么? 我的代碼是這樣的。
var canvas1 = document.getElementById("canvas1"); // Get the first canvas Element
var canvas2 = document.getElementById("canvas2"); // Get the second canvas element
if (typeof G_vmlCanvasManager != 'undefined') {
canvas1 = G_vmlCanvasManager.initElement(canvas1); // Initialise with excanvas
canvas2 = G_vmlCanvasManager.initElement(canvas2);
}
if (canvas1.getContext) {
var ctx1 = canvas1.getContext("2d");
var ctx2 = canvas2.getContext("2d");
var img = new Image();
img.onload = function () {
ctx1.drawImage(this, 0, 0, 200, 200); // Draw the image on first canvas
ctx2.drawImage(canvas1, 0, 0, 200, 200); // Draw the image on to the second canvas using the first canvas
}
img.src = "image1.jpg";
}
在IE8及以下版本的瀏覽器中無法使用。 如何解決這個問題?
我會嘗試這樣的事情:
function canvasToImage( canvas ) {
var img = new Image();
img.src = canvas.toDataURL();
return img;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.