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
沒問題,歡迎光臨。 –