• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Width of Imported Image

Explorer ,
Feb 07, 2020 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

385

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
community guidelines

correct answers 1 Correct answer

Explorer , Feb 07, 2020 Feb 07, 2020

Votes

Translate

Translate
Explorer ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

Votes

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
community guidelines
Explorer ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines