0

我有一个小问题,我有以下 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;
    } 
4

1 回答 1

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;
    // ...
} 
于 2013-05-09T09:21:46.447 回答