System.Drawing.Image.FromFile()不起作用(?) [英] System.Drawing.Image.FromFile() does not work (?)

查看:65
本文介绍了System.Drawing.Image.FromFile()不起作用(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 9.0. .net框架版本为2.0.我需要使用System.Drawing.Image.FromFile()方法.编译器报告此功能不存在.在文档中,该功能写在文件"System.Drawing.dll"中.我已经包含了该文件,但错误仍然没有消失.整个代码如下所示:

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 System.Drawing.Image does not contain a definition for ''FromFile()''."
我需要使用此功能.谁能帮助我解决我的问题.在此先感谢您.


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.

推荐答案

如何包含System.Drawing.dll-您是否在项目上单击鼠标右键并使用添加引用来添加对系统的引用.图纸装配?

System.Drawing.Image.FromFile声明为

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
)



因此,据我所知,您的代码应该编译...

您不是在代码中创建Image类的实例,而是在FromFile内的某个地方创建.

问候
Espen Harlinn



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


由于您未在VS9.0上使用.net 4.0框架,因此只需检查.net 2.0是否支持您要提供的重载.即使方法名也是如此是现有的并且不支持重载,它可能抛出不包含防御的问题.我在vs9.0中执行了您的代码行,并且运行得很好.
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.


应该是:

It''s supposed to be:

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



Image类是一个抽象类,无法实例化.

我认为使用完全限定的路径而不是仅使用文件名来检索文件也是明智的.



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.


这篇关于System.Drawing.Image.FromFile()不起作用(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆