- Home /
Get size of UI Image at runtime
I'm trying to get the true size in pixels of an image at runtime. The image is set to scale automatically. I tried using the rectTransform.size but it only returns the original size of the image before any scaling is applied. How do I get the true size after the automatic scaling is applied ?
Did you ever find out the answer to this question? If so please post it
Answer by Komayo · Aug 19, 2017 at 02:46 PM
Try:
Image xptoExample;
realWidth = xptoExample.sprite.rect.width;
realHeight = xptoExample.sprite.rect.height;
Answer by AdnanSiddique · Jul 13, 2020 at 01:45 PM
GetComponent().rect.width
GetComponent().rect.height
@a436t4ataf try this, it is working for me Unity 2018 LTS
Your answer
Follow this Question
Related Questions
How do i make my ui elements stay the same size and position on all andorid devices? 1 Answer
UI Canvas Image parented to main camera only moves in x and z 0 Answers
Resizing UI Image but with minimum width 2 Answers
Canvas Screen Space Issue 1 Answer
I can't see the all of UI in the phone 0 Answers