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 ?


 Image xptoExample;

realWidth = xptoExample.sprite.rect.width;
realHeight = xptoExample.sprite.rect.height;
int width = GetComponent<RectTransform>().rect.width;
int width = GetComponent().rect.width;
int height = GetComponent().rect.height;

@a436t4ataf try this, it is working for me Unity 2018 LTS