Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 'System.Windows.Controls.Image' does not contain a definition for 'FromFile'

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

Scheduled Pinned Locked Moved C#
csharpquestionwpfgraphicshelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jasonalien
    wrote on last edited by
    #1

    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'

    Richard DeemingR D S 3 Replies Last reply
    0
    • J jasonalien

      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'

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      At a guess, do you have a control on your window with the name set to "Image"? Try creating an alias for the Image type name, or using the fully qualified type name:

      using DrawingImage = System.Drawing.Image;
      ...
      DrawingImage image1 = DrawingImage.FromFile(filename1);

      // -or-

      var image1 = System.Drawing.Image.FromFile(filename1);


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • J jasonalien

        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'

        D Offline
        D Offline
        Deflinek
        wrote on last edited by
        #3

        Your codes contains

        using System.Drawing

        but you are getting error from System.Windows.Controls namespace. Most likely there is either some namespace confusion for compiler. Try specify the namespace explicitly in the last line:

        Image image1 = System.Drawing.Image.FromFile(filename1);

        -- "My software never has bugs. It just develops random features."

        J 1 Reply Last reply
        0
        • D Deflinek

          Your codes contains

          using System.Drawing

          but you are getting error from System.Windows.Controls namespace. Most likely there is either some namespace confusion for compiler. Try specify the namespace explicitly in the last line:

          Image image1 = System.Drawing.Image.FromFile(filename1);

          -- "My software never has bugs. It just develops random features."

          J Offline
          J Offline
          jasonalien
          wrote on last edited by
          #4

          Thank you for your reply, I did what you said and I get this : The type or namespace name 'Image' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?) Thanks.

          D 1 Reply Last reply
          0
          • J jasonalien

            Thank you for your reply, I did what you said and I get this : The type or namespace name 'Image' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?) Thanks.

            D Offline
            D Offline
            Deflinek
            wrote on last edited by
            #5

            Do you reference System.Drawing.dll in your project?

            -- "My software never has bugs. It just develops random features."

            1 Reply Last reply
            0
            • J jasonalien

              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'

              S Offline
              S Offline
              Swinkaran
              wrote on last edited by
              #6

              I'm sorry if I am wrong, but I would rather do this as follows. I guess this is a better way of loading the file dynamically

              Uri filename1 = new Uri(@"C:\images\mainicon.jpg");
              image1.Source = new BitmapImage(filename1);

              Is this something helpful?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups