简体   繁体   中英

Windows Forms equivalent code for the following code WPF

I have a small problem, I have the following WPF code and I try to import in Windows Forms. Here is the WPF code :

在此处输入图片说明

And here I try to modify the WPF code to make it functional in Windows Forms :

在此处输入图片说明

So, at pictureBox1.Image = bframe I get the following error : "Cannot implicity convert type 'Systems.Windows.Media.Imaging.BitmapFrame' to 'System.Drawing.Image' " . It's the first time I deal with WPF so I need a little help. Thanks .

Here's the code, sorry for the pictures :

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;
    } 

Use System.Drawing.Bitmap instead of BitmapFrame . It has a constructor that takes a path.

In the future, please post the code here. I'd post a complete solution, if I could copy it and change just the one line, but I don't feel like typing all of it from a posted image.

Edit:

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;
    // ...
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM