0
当我创建一个BitmapImage时,Height参数给了我...宽度。 这是我的代码,如果你看到错误,我不能。C#获取BitmapImage高度
private void button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp";
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if (openFileDialog.ShowDialog() == true)
{
BitmapImage image = new BitmapImage(new Uri(openFileDialog.FileName));
int maxHeight = 100;
if(image.Height != maxHeight)
{
MessageBox.Show("Error with the size");
return;
}
FileTextBlock.Text = openFileDialog.FileName;
ImageWPF.Source = imageEndo;
}
}
试图用一个高度为100,宽度为16的bitrmap图像,在image.Height中获得16。
使用PixelHeight代替https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.pixelheight(v=vs.110).aspx –
工作!谢谢 ! – betsou
没问题,欢迎光临。 –