javascript - setting canvas with image dimetions -


i trying set canvas picture background. want make image variable that's different discussion.

here code.

var canvas = document.getelementsbytagname('canvas')[0];  var img = document.createelement('img');  img.onload = function () { alert(img.width + ' x ' + img.height); };  img.src='images/maps/de_dust2.jpg';  canvas.width  = img.width; canvas.height = img.height; 

when page loads alert correct pixel height , width canvas not shown.

any appreciated.

var canvas = document.getelementsbytagname('canvas')[0];  var img = document.createelement('img');  img.onload = function () {     // need have thes in onload, have img width, height > 0     canvas.width  = img.width;     canvas.height = img.height;     alert(img.width + ' x ' + img.height); };  img.src='images/maps/de_dust2.jpg'; 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -