我有一个小问题,我有以下WPF代码,我尝试在Windows窗体中导入。 这是WPF代码:
在这里,我尝试修改WPF代码,使其在Windows窗体中正常运行:
因此,在pictureBox1.Image = bframe我得到以下错误:“无法将类型'Systems.Windows.Media.Imaging.BitmapFrame'转换为'System.Drawing.Image'”。这是我第一次处理WPF,所以我需要一些帮助。谢谢。
这是代码,对不起图片:
private void button1_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog objDialog = new Microsoft.Win32.OpenFileDialog();
objDialog.Filter = "Only JPG File|*.jpg";
objDialog.ShowDialog();
textBox1.Text = objDialog.FileName;
Uri path = new Uri(textBox1.Text);
BitmapFrame bFrame = BitmapFrame.Create(path);
ViewedPhoto.Source = bFrame;
ExifMetaInfo objMetaInfo = new ExifMetaInfo(path);
lblBrand.Content = objMetaInfo.EquipmentManufacturer;
lblModelName.Content = objMetaInfo.CameraModel;
lblAparature.Content = objMetaInfo.LensAperture;
lblCreation.Content = objMetaInfo.CreationSoftware;
lblFocalLength.Content = objMetaInfo.FocalLength;
lblHeight.Content = objMetaInfo.Height;
lblWidth.Content = objMetaInfo.Width;
lblISO.Content = objMetaInfo.IsoSpeed;
}
答案 0 :(得分:1)
使用System.Drawing.Bitmap
代替BitmapFrame
。它有一个带路径的构造函数。
将来,请在此处发布代码。我发布了一个完整的解决方案,如果我可以复制它并只更改一行,但我不想从发布的图像中键入所有内容。
编辑:
private void button1_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog objDialog = new Microsoft.Win32.OpenFileDialog();
objDialog.Filter = "Only JPG File|*.jpg";
objDialog.ShowDialog();
textBox1.Text = objDialog.FileName;
Bitmap bitmap = new Bitmap(objDialog.FileName);
pictureBox1.Image = bitmap;
// ...
}