Skip to main content
Inspiring
February 7, 2020
Answered

Width of Imported Image

  • February 7, 2020
  • 1 reply
  • 572 views

I want to know the width of an image I am importing into a variable. I do not understand why I can't get this, but can get the x,y. This is an image, not a shape, so I don't see why the width and height are undefined.

 

var image = new createjs.Bitmap("Assets/svg/MLC_Lesson1_043_en.png");
alert(image.width);

The reason I want to figure out the width is that it seems that when I import and addChild(image) to a movieclip, the image winds up smaller than it should, but I want to make sure. It's not because of the size of the movieclip.

This topic has been closed for replies.
Correct answer RyanS_Extron17202589

Nevermind. Answer is here: https://stackoverflow.com/questions/14813279/how-to-change-bitmap-width-and-height-in-easeljs 

1 reply

RyanS_Extron17202589AuthorCorrect answer
Inspiring
February 7, 2020
Inspiring
February 7, 2020

This is better since waits for load: https://stackoverflow.com/questions/29647157/how-to-get-bitmap-width-height-createjs 

 

var img = new Image();
img.onload = function() {
	// gets called when the img is loaded
	alert(img.width+"    "+img.height);
};
img.src='Assets/svg/04a_MultiPurpose_Solution-exported.svg';