Skip to content

System.Drawing.Image.FromFile()

a b

Asked Apr 28, 2007, 6:08 AM EDT3 answers
Share
LinkedInX
Hi guys, Im relatively new to C# and I was wondering if ye could help me out with this problem. Its absolutely doing my nut in. Im trying to display a jpeg in my pictureBox1 which is stored locally on my machine. Im using: pictureBox1.Image = System.Drawing.Image.FromFile(@"blah blah blah"); or I also tried Image img = Image.FromFile(@" ... "); but everytime I keep getting the error to the effect " System.Drawing.Image does not contain a definition for 'FromFile' ". I cant understand it. Every program iv searched on the net uses this but my program wont allow me. What do I need to do to allow it to work? Currently Image. only gives me 3 options, .Equals, .FromHbitmap, and .ReferenceEquals. What can I do to solve this error or am I going the wrong way about displaying the file altogether?? I also tried, Bitmap b = new Bitmap(directory + @"Point1.jpg"); which worked but threw an exception whilst debugging saying it cant find part of the file or directory. Any help would be MUCH appreciated. Im really tied for time here. Cheers!

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    What version of C# are you using?    I'm not required to use the @ symbol when defining a string.  I can create a bitmap by the following: Bitmap bmpPhoto = new Bitmap("C:\\" + photoName + ".jpg")

    I wish you luck!
       Richard
    0
  • 0
    Im using C#, Microsoft Visual Studios 2005.
    0
  • 0
    Thats the same version I have.  Very strange.  See if you can do this:  Create a Jpg image named "Test" and put it right under the "C:"  directory.  Now try this code that works for me:

    System.Drawing.Image imgTest = System.Drawing.Image.FromFile("C:\\Test.jpg");

    If that don't work get away from your computer because it's fixing to blow up!  :->
    Let me know how it turns out.

    Cheers!
    Richard

    0