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

HTML5 Canvas - Constrain image/SVG scaling to stage size

Engaged ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

I am using createjs.Bitmap to add an SVG to the stage.

 

The project is using a responsive layout..

 

The problem is the SVG does not scale relative to the stage and other elements around it.

 

var patientImagePath = data['patient_image_path']

patientImage = new createjs.Bitmap(patientImagePath);

patientImage.x = 96;
patientImage.y = 36.05;
patientImage.scaleX = 0.16;
patientImage.scaleY = 0.16;

root.patientDetailsModal.addChild(patientImage);

'Normal' view on large monitor:

 

2022-04-08_9-18-33.jpg

 

and after reducing the browser size using dragging (not using zoom...).

 

2022-04-08_9-18-58.jpg

 

Any solutions?

Views

223

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
Engaged ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

If I just import the SVG to the stage, without using new createjs.Bitmap, then the SVG scales fine.

 

But I need to load the SVGs dynamically...

 

 

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
Engaged ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

Also, looking at the SVG code, the viewBox is:

 viewBox="0 0 151.5 163.7"

 

But if I don't apply the scale at:

patientImage = new createjs.Bitmap(patientImagePath).set({scaleX: 0.16, scaleY: 0.16}); 

 

Then the image is loaded in a really enormous size.  I think the problem of scaling might be dealt with if the SVG just loaded in its viewbox size...

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
Engaged ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

UPDATE

 

Changed the format to PNG, and without scaling, comes in at it's original size (151.5 x 163.7), which is perfect. However, I want to use SVG, not PNG.

 

It seems the SVG just gets scaled up to a huge size despite the viewport size...

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
Engaged ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

So how do I get SVG to load at its original size as per the viewbox with any scaling?

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
Engaged ,
Apr 10, 2022 Apr 10, 2022

Copy link to clipboard

Copied

LATEST

Anything?

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