C#图像保存路径 [英] C# image saving path

查看:106
本文介绍了C#图像保存路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#help



朋友我需要帮助我的C#简单项目。当我保存我的图像时,我使用了这个直接路径。但是当我改变这个项目时路径也需要更改的文件夹。

你们可以建议实现这个的好方法吗?



pictureBox3.Image.Save(@ C:\ Users\Thilan \Desktop \ Our Project \OtsuThreshold1.2 \Images\test2.jpg,ImageFormat.Jpeg);

C# help

friends i need help for my C# simple project.when i'm saving my image i used this direct path.but when i change this project folder that path also needed to be change.
can u guys suggest good way to implement this?

pictureBox3.Image.Save(@"C:\Users\Thilan\Desktop\Our Project\OtsuThreshold1.2\Images\test2.jpg", ImageFormat.Jpeg);

推荐答案

您应该使用 Server.MapPath方法 [ ^ ]映射文件夹路径。

试试这个:

You should use Server.MapPath Method[^] to map the folder path.
Try this:
String FilePath;
FilePath = Server.MapPath("~/Images/test2.jpg");
pictureBox3.Image.Save(FilePath, ImageFormat.Jpeg);





请参阅:ASP.NET MapPath [ ^ ]








您可以使用:



Please see : ASP.NET MapPath[^]




You can use :

string FilePath= Application.StartupPath + "\\Images\\test2.jpg";
pictureBox3.Image.Save(FilePath, ImageFormat.Jpeg);



您还可以使用: Path.GetDirectoryName方法 [ ^ ]



- Amit


解决方案1仅适用于 System.Windows.Forms ,因为它使用系统.Windows.Forms.Application ,即使在问题中使用了Forms标签,这已经不够好了。有不同的其他方法可以找到这条路径,有些也不是通用的,因为它们取决于应用程序的托管方式(例如,它可能使它不适合Windows服务)。



我在过去的答案中描述的这个解决方案没有这些缺点:

如何查找我的程序目录可执行目录),

如何查找我的程序目录当前目录,特殊文件夹



-SA
The Solution 1 is only good for System.Windows.Forms, as it uses System.Windows.Forms.Application, which is already not good enough, even if "Forms" tag was used in the question. There are different other ways to find out this path, and some are also not universal as they depend on how the application is hosted (it may make it unsuitable for, for example, Windows Services).

This solution I described in my past answer does not have those disadvantages:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

—SA


这篇关于C#图像保存路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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