Search code examples
c#imagesize

Find out width and height of an Image in C#


I am currently trying to get the Size and reshape my rectangle to the actual size of the image (width and height). However when i use Image.Height or Image.Width its always 0. The picture that is displayed when i start the program takes up the entire screen

            Uri imageUri = new Uri(FileListe[position]);
            Image Bild = new Image();
            Bild.Source = new BitmapImage(imageUri);

            Interface.Width = Bild.Width; 
            Interface.Height = Bild.Height;

            brush.ImageSource = new BitmapImage(imageUri);

            Interface.Fill = brush;

Solution

  • have you tried using the bitmap image to get width and height from?

    For example:

    BitmapImage bitmapBild = new BitmapImage(imageUri);
    Interface.Width = bitmapBild.Width;
    Interface.Height = bitmapBild.Height;