帮忙看不看 二句话有什么不同?

raozr 2003-05-15 12:37:17
imgLeft = new Bitmap( GetType(), "left.png" );
imgLeft = Image.FromFile(@"E:\test\WindowsApplication2\left.png");


这二句话, 有什么不同.

为什么用上面那句, 总说文件找不到.
而图片文件就放在项目的根目录下.
在VS.net 中还需要做什么, 我才能用第一句话.
...全文
38 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zydchina 2003-05-15
  • 打赏
  • 举报
回复
应该放在bin的目录中
brightzh 2003-05-15
  • 打赏
  • 举报
回复
你的exe在debug目录下面。
所以找不到。
可以把该文件拷贝到exe这个目录里面
LiSDN 2003-05-15
  • 打赏
  • 举报
回复
什么要用GetType()啊,不用也可以
LiSDN 2003-05-15
  • 打赏
  • 举报
回复
imgLeft = new Bitmap( GetType(), System.Environment.CurrentDirectory.ToString()
+"\\left.png" );
LiSDN 2003-05-15
  • 打赏
  • 举报
回复
EXE所在的目錄名
System.Environment.CurrentDirectory.ToString()
ETstudio 2003-05-15
  • 打赏
  • 举报
回复
imgLeft = new Bitmap( GetType(), "..\\..\\left.png" );
看看这样可以吗,我也没用过
开心就好 2003-05-15
  • 打赏
  • 举报
回复
从指定的资源初始化 Bitmap 类的新实例。

[Visual Basic]
<Serializable>
<ComVisible(True)>
Public Sub New( _
ByVal type As Type, _
ByVal resource As String _
)
[C#]
[Serializable]
[ComVisible(true)]
public Bitmap(
Type type,
string resource
);
[C++]
[Serializable]
[ComVisible(true)]
public: Bitmap(
Type* type,
String* resource
);
[JScript]
public
Serializable
ComVisible(true)
function Bitmap(
type : Type,
resource : String
);
参数
type
用于提取资源的类。
resource
资源名。
要求
平台: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family

请参见
Bitmap 类 | Bitmap 成员 | System.Drawing 命名空间 | Bitmap 构造函数重载列表
raozr 2003-05-15
  • 打赏
  • 举报
回复
我看别人写的代码, 都是直接就这么写
imgLeft = new Bitmap( GetType(), "left.png" );
是不是和资源有什么关系.



111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧