Forum Xamarin.Forms

How can I get the image size

Hi all,

How can I get a image size from an ImageSoure, I used these codes but cannot work

    public static Rectangle GetImageSizeFromSource(ImageSource source)
        Rectangle res = new Rectangle (0,0,0,0);
        Image loadImage = new Image ();
        loadImage.Source = source;
        res.Width = loadImage.Width;
        res.Height = loadImage.Height;
        return res;


  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    @JesseJiang can I ask why do you need the image's width and height?
    I am thinking there might be another solution to what you're trying to do.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    The image itself loads asynchronously so you have to wait for it to load. Normally you would just let the Image view size itself automatically once the image loads so there's no need to ask it how big the image is. What are you trying to do?

Sign In or Register to comment.