添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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. 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 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. 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. Still U didn't get u can try like this
System.Drawing.Image image = new Bitmap(file.FullName);
imageList1.Images.Add(image);
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •