string startupPath = System.Windows.Forms.Application.StartupPath;
string solutionPath = startupPath +@" \..\..\..\";
如果在工程目录下建立了一个Images目录,需要取其中的a.jpg,那么只需要:
Bitmap image = new Bitmap(solutionPath + @"images\a.jpg");
如果是在工程内部,还有更直接的方式,比如:这么写也是可以的:
Bitmap image = new Bitmap(@"..\..\..\images\a.jpg");
OK.

本文介绍了一种在C#应用程序中加载图片文件的有效方法。通过使用相对路径和绝对路径,可以轻松地从项目目录中获取所需的图像资源。文中还提供了一个简单的示例来演示如何实现这一功能。

被折叠的 条评论
为什么被折叠?



