Highlighted

Width of Imported Image

Explorer ,
Feb 07, 2020

Copy link to clipboard

Copied

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.

TOPICS
Code, How to, Import and export, Performance

Views

200

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Width of Imported Image

Explorer ,
Feb 07, 2020

Copy link to clipboard

Copied

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.

TOPICS
Code, How to, Import and export, Performance

Views

201

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 07, 2020 0
Explorer ,
Feb 07, 2020

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 07, 2020 0
Explorer ,
Feb 07, 2020

Copy link to clipboard

Copied

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';

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 07, 2020 0