FreshBits
FreshBits

Reputation: 1013

Unable to load image in canvas( using Excanvas in ie8)

Im using excanvas to use canvas element in ie8 but i can't able to load image in canvas.

my code is

var el = document.getElementById('cavasid');
G_vmlCanvasManager.initElement(el);
var context = el.getContext('2d');


 var img = new Image();
 img.onload = function() {
 context.drawImage(img, 0,0);
 };
 img.src = "jj.png";

Upvotes: 1

Views: 626

Answers (1)

KiranPalode
KiranPalode

Reputation: 498

Make sure you have added excanvas.js in the head section and then try the below code

  var el = document.getElementById('cavasid');
 if (typeof G_vmlCanvasManager != 'undefined') {
     el = G_vmlCanvasManager.initElement(el);
 }

 if (el.getContext) {
     var context = el.getContext('2d');


     var img = new Image();
     img.onload = function () {
         context.drawImage(img, 0, 0);
     };
     img.src = "jj.png";
 }

also give some width and height to your canvas like

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

Upvotes: 1

Related Questions