Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I am using visual studio 9.0. The .net framework version is 2.0. I need to use the System.Drawing.Image.FromFile() method. The compiler reports that this function does not exist. In documention, it is written that this function is in file "System.Drawing.dll". I have included that file but still the error has not gone. Whole code looks like below:
C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Resources;
namespace Res
{
    class Program
    {
        static void Main(string[] args)
        {
            Image img = System.Drawing.Image.FromFile("aa.gif");
        }
    }
}

The compiler error I am getting is "The System.Drawing.Image does not contain a definition for 'FromFile()'."
I need to use this function. Can anyone help me to ressolve my issue. Thanks in advance.
Posted
Updated 9-Jan-11 14:18pm
v2

How did you include System.Drawing.dll - did you right click on your project and use add reference to add a reference to the System.Drawing assembly?

System.Drawing.Image.FromFile is declared as

C#
public static Image FromFile(
    string filename
)


so, as far as I can tell, your code should compile ...

You are not creating an instance of the Image class in your code, that happens somewhere inside FromFile.

Regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Dalek Dave 9-Jan-11 14:25pm    
Good Call.
Espen Harlinn 9-Jan-11 16:38pm    
Thanks Dalek!
Sergey Alexandrovich Kryukov 9-Jan-11 20:15pm    
This is good answer - my 5. As to v.2.0 -- I confirm the method is supported, see my answer.
Shah Rukh Qasim 10-Jan-11 1:42am    
Thanks for your answer. Perhaps that the dll I was referencing was not compelete. I downloaded System.Drawing.dll from internet and referenced it. The method worked. Thanks a lot for your support as I thought that this method would be removed from newer .net version. Thanks once again.
As you are not using .net 4.0 framework along VS9.0,just check if the overload you are trying to provide is supported in .net 2.0 .Even if the name of method is existing & overload not supported,it may throw does not contain defenition.I executed your line of code in my vs9.0 & it runs perfectly fine.
 
Share this answer
 
Comments
Dalek Dave 9-Jan-11 14:25pm    
Good Answer.
Sergey Alexandrovich Kryukov 9-Jan-11 20:16pm    
All right, my 5. As to v.2.0 -- I confirm the method is supported, see my answer.
Anupama Roy 10-Jan-11 13:00pm    
Thank you!
It's supposed to be:

C#
Bitmap img = (Bitmap)Image.FromFile("aa.gif", true);


The Image class is an abstract class and cannot be instantiated.

I think it would also be wise to use the fully qualified path to retrieve the file instead of just the file name.
 
Share this answer
 
v3
I thought this method does not compile in Framework 2.0, but I immediately found a confirmation it does exist:

http://msdn.microsoft.com/en-us/library/system.drawing.image.fromfile(v=vs.80).aspx[^]

This method even existed in Framework v.1.1:

http://msdn.microsoft.com/en-us/library/system.drawing.image_members(v=VS.71).aspx[^]

So, please check things up.
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 10-Jan-11 10:46am    
Who is so clever?
Hi ,

Still U didn't get u can try like this

System.Drawing.Image image = new Bitmap(file.FullName);
imageList1.Images.Add(image);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900