0

If I open an image using this code I get the correct width and height:

Bitmap bitmap = new Bitmap(@"C:\Users\Javier Escribano\Desktop\sample.png");

var imageHeight = bitmap.Height; //1270
var imageWidth = bitmap.Width; //1650

but If I use this code to show an image on WPF control the image is automatically resized. I want to keep the original dimensions:

ImageSource img = (ImageSource)new ImageSourceConverter().ConvertFromString(
                        @"C:\Users\Javier Escribano\Desktop\sample.png");
this.image.Source =  img;
this.image.Width = img.Height; //1057
this.image.Height = img.Width; // 817
1
  • 1
    Use img.PixelWidth and img.PixelHeight.
    – Clemens
    Commented Oct 12, 2016 at 12:13

1 Answer 1

1

This is very likely caused by a mismatch of ppi (pixels per inch) of the png image and the dpi (dots per inch) of WPF. Scott Hanselman has a good post about it here.

Not the answer you're looking for? Browse other questions tagged or ask your own question.