不使用对话框C#保存图像 [英] C# Save image without using Dialog
问题描述
我无法保存用户上传的图片我的标志的文件,当用户按下保存队的窗体上。
I am having trouble saving a user uploaded image to my "logos" file when the user presses "Save Team" on my form.
有关你获得哪些应用程序我在这里提供截图,在按下加入团队中的所有文本框数据写入的品酒师一个文本文件,我想要的图像自动保存到预定义文件夹逻各斯,但是我得到的GDI +错误,每当我按保存。
For you to get a taster of what the application does I have provided a screenshot here, upon pressing add team all the text box data is written to a text file and I want the image to automatically save into a predefined folder "logos", however I get the GDI++ error whenever I press save.
通过一些看完后在网络上老的线程,我发现它可以通过一些事情,例如文件权限,文件大小,文件名,甚至打开的流引起的。
After reading through a few old threads on the web, I found that it could be caused by a few things such as file permissions, file size, the files name or even an open stream.
下面是我目前使用的保存我的文件,该文件会提示错误代码:
Below is the code I am currently using to save out my file which prompts the error:
private void btnAddTeam_Click(object sender, EventArgs e)
{
//VALIDATION FOR TEXT FILE AND OTHER STUFF HERE...
//SAVE THE IMAGE FILE
string filePath = picTeamLogo.ImageLocation;
Image tempImage = Image.FromFile(filePath);
tempImage.Save(@"../logos/");
}
如果您正在查看的屏幕截图,请不要被兵工厂混淆。 PNG我知道这是不完整的文件路径,其转化是在另一种方法进行处理,如只需要文件名被写入到文本文件
If you are viewing the screenshot, please do not get confused by "arsenal.png" I am aware that that is not the full file path, its conversion is handled in another method, as only the filename is required to be written to the text file.
如果有人对我要去的地方错了任何想法,那么请点我在正确的方向,模糊的错误,如GDI一个我刚刚收到是这样一个头痛!
If anybody has any ideas on where I am going wrong then please point me in the right direction, vague errors such as the GDI one I just received are such a headache!
亚历克斯。
Alex.
推荐答案
这是因为你没有指定的文件名保存功能!
that's because you have not specified the file name for save function !
来看看这个:
string filePath = picTeamLogo.ImageLocation;
FileInfo fi = new FileInfo(filePath);
Image tempImage = Image.FromFile(fi.FullName);
tempImage.Save(@"../logo/" + fi.Name);
现在它正常工作
这篇关于不使用对话框C#保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!