Hello, when I try to insert an image to a canvas in a certain ratio, the image is getting the ratio of the canvas, instead of keeping it’s original ratio. How can I change that? I mean that the image will only take a part of the canvas, and the rest will be white.
Thanks in advance!
You will have to use an imageSprite for that. Images will always take the dimensions of the canvas when put in the background.
The workaround depends on the orientation of your image, (portrait or landscape).
This will work if your image is in landscape mode:
First give your canvas width the same width of your screen (width = fill parent).
Then use the simple formula of aspect ratio: set Canvas.Height to (ImageOriginalHeight / ImageOriginalWidth ) x Canvas.Width
to calculate the canvas height.
Now the image should fit in the width of your screen without distortion.
If your picture is in portrait mode, use the same formula but switching Canvas.Width and Canvas.Height.
That will give you the height of your canvas to show the image without distortion.
This can be also applied to sprites, if you want to use @TIMAI2’s solution.
Hi, Do you have an example with simple blocks perhaps? Thanks