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
Post a Comment