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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -