Click here to Skip to main content
12,696,493 members (30,522 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# .NET
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:
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 9-Jan-11 4:23am
Updated 9-Jan-11 15:18pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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

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
  Permalink  
v2
Comments
Dalek Dave 9-Jan-11 14:25pm
   
Good Call.
Espen Harlinn 9-Jan-11 16:38pm
   
Thanks Dalek!
SAKryukov 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Comments
SAKryukov 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!
Dalek Dave 9-Jan-11 14:25pm
   
Good Answer.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It's supposed to be:

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.
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
v3
Comments
SAKryukov 10-Jan-11 10:46am
   
Who is so clever?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Hi ,

Still U didn't get u can try like this

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 3 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100