0

Hello,
I have this C# code but I get the error in the title. on the "FromFile" part. I want to simply publish images in my PC on a WPF application.
How can I get rid of this error?
Thanks.

Code :

using System.Drawing;

namespace Photo
{
   public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();


            string filename1 = @"C:\images\mainicon.jpg";
            Image image1 = Image.FromFile(filename1);
        }
    }
}

Error :

'System.Windows.Controls.Image' does not contain a definition for 'FromFile'

2
Contributors
1
Reply
8
Views
2 Years
Discussion Span
Last Post by deceptikon
0

It looks like the compiler is interpreting Image as System.Windows.Controls.Image rather than System.Drawing.Image. The error is correct in that the target class doesn't have a FromFile method.

I'm a bit surprised that you're not getting an ambiguity error instead, but a quick fix would be to fully qualify the class:

var image1 = System.Drawing.Image.FromFile(filename1);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.