Home > Blockchain >  Find out width and height of an Image in C#
Find out width and height of an Image in C#

Time:11-09

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;

CodePudding user response:

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;

CodePudding user response:

When using WPF you need to use the PixelWidth and PixelHeight if you want the actual number of pixels in the image, since Width/Height refers to the size of control.

So keep in mind what context you are working in. A BitmapImage is quite different from a System.Drawing.Bitmap.

  • Related