且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取图像路径

更新时间:2023-11-29 15:51:40

我认为您的问题是您是否可以摆脱不提供完整路径的麻烦.如果是这样,则不会.始终***提供图像的完整路径.

您会发现,即使您未指定完整路径,但并不依赖于此行为,有时它仍然可以正常工作.当前目录,搜索目录等在运行时不可预测,因此您需要始终指定完整路径.


----------

为了回应您的评论,这里介绍了如何在应用程序目录中获取图像文件夹的路径(使用示例文件夹和图像名称).

I reckon your question is whether you can get away with not providing the full path. If so, no. It''s always best to provide the full path to the image.

You will find that sometimes it works okay even if you don''t specify the full path, but don''t depend on this behavior. The current directory, search directories etc. are not predictable at runtime, so you need to specify the full path always.


----------

In response to your comment, here''s how you can get the path to the image folder in your application directory (using your example folder and image names).

string imagePath = Path.Combine(Path.GetDirectoryName(
    Assembly.GetExecutingAssembly().Location), @"pic\pro.png");

>