Problem with IE, getContext() and drawImage()

1,342 views
Skip to first unread message

Santi!#

unread,
Mar 23, 2009, 1:43:57 PM3/23/09
to google-excanvas
Hello I try to draw a simple image into a canvas tag. I'm using
ExCanvas, and can’t get any output. I attach the code. It say that de
"The object does not accept the property or method" refer to getContext
(). Is like IE doesn’t recognize excanvas.js


/*************************************/
var imgBackground = new Image();
imgBackground.src = 'bg.png';
imgBackground.id = 'bg_meter';

var canvasOutput = document.createElement('canvas');
canvasOutput.id = 'canvasOutput';

var container = document.getElementById(div);
container.appendChild(canvasOutput);

var imgWidth = imgBackground.width;
var imgHeight = imgBackground.height;

canvasOutput.width = imgBackground.width;
canvasOutput.style.width = canvasOutput.width + 'px';
canvasOutput.height = imgBackground.height;
canvasOutput.style.height = canvasOutput.height + 'px';
canvasOutput.id = 'img_meter';

var bgCtx = canvasOutput.getContext('2d');
bgCtx.save();
bgCtx.drawImage(imgBackground, 0, 0, imgWidth, imgHeight);
bgCtx.restore();

/*************************************/

Can anyone help me?

Thanks for advanced.

Erik Arvidsson

unread,
Mar 23, 2009, 4:18:14 PM3/23/09
to google-...@googlegroups.com
You need to use initElement. See inline

2009/3/23 Santi!# <tia...@gmail.com>:
>
> Hello I try to draw a simple image into a canvas tag. I'm using
> ExCanvas, and can’t get any output. I attach the code. It say that de
> "The object does not accept the property or method" refer to getContext
> (). Is like IE doesn’t recognize excanvas.js
>
>
> /*************************************/
>        var imgBackground = new Image();
>        imgBackground.src = 'bg.png';
>        imgBackground.id = 'bg_meter';
>
>        var canvasOutput = document.createElement('canvas');
>        canvasOutput.id = 'canvasOutput';
>
>        var container = document.getElementById(div);
>        container.appendChild(canvasOutput);

if (typeof G_vmlCanvasManager != 'undefined') {
G_vmlCanvasManager.initElement(canvasOutput);
}

>
>        var imgWidth = imgBackground.width;
>        var imgHeight = imgBackground.height;
>
>        canvasOutput.width = imgBackground.width;
>        canvasOutput.style.width = canvasOutput.width + 'px';
>        canvasOutput.height = imgBackground.height;
>        canvasOutput.style.height = canvasOutput.height + 'px';
>        canvasOutput.id = 'img_meter';
>
>        var bgCtx = canvasOutput.getContext('2d');
>        bgCtx.save();
>        bgCtx.drawImage(imgBackground, 0, 0, imgWidth, imgHeight);
>        bgCtx.restore();
>
> /*************************************/
>
> Can anyone help me?
>
> Thanks for advanced.
>
> >
>



--
erik

Santi!#

unread,
Mar 25, 2009, 10:11:42 AM3/25/09
to google-excanvas
Thanks, this work perfect!
Reply all
Reply to author
Forward
0 new messages