如果我使用此代码打开图像,我会得到正确的宽度和高度:
Bitmap bitmap = new Bitmap(@"C:\Users\Javier Escribano\Desktop\sample.png");
var imageHeight = bitmap.Height; //1270
var imageWidth = bitmap.Width; //1650
但如果我使用此代码在WPF控件上显示图像,则会自动调整图像大小。我想保留原始尺寸:
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