如何保存从WebClient方法下载的图像文件 [英] How to save image file which is downloaded from WebClient method

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

问题描述

大家好



i使用以下代码通过WebClient获取图片



 WebClient wc =  new  WebClient(); 
byte [] bytes = wc.DownloadData( http://xyz.com/Image/1.jpg);
MemoryStream ms = new MemoryStream(字节);
var image = System.Drawing.Image.FromStream(ms);





工作正常,但我想将WebClient下载的文件保存到我的项目文件夹中。如何实现这一目标。



谢谢

解决方案

用户image.Save(filePath)?



对于你的项目文件夹......你的意思是应用程序文件夹还是你的开发人员项目?



申请文件夹:

System.Reflection.Assembly.GetExecutingAssembly()。CodeBase



您的开发人员项目必须放入配置文件或以其他方式保存在某些应用程序设置中。


 WebClient wc =  new  WebClient(); 
byte [] bytes = wc.DownloadData( http://xyz.com/Image/1.jpg);
System.IO.File.WriteAllBytes( your_path + your_filename + fileextention,bytes) ;


Hello everyone

i am using the following code to fetch image through WebClient

WebClient wc = new WebClient();
           byte[] bytes = wc.DownloadData("http://xyz.com/Image/1.jpg");
           MemoryStream ms = new MemoryStream(bytes);
           var image = System.Drawing.Image.FromStream(ms);



that is working fine but i want to save the WebClient downloaded file into to my project folder. how to achieve this.

Thanks

解决方案

User image.Save(filePath)?

For your project folder...do you mean application folder or your developer project?

Application folder:
System.Reflection.Assembly.GetExecutingAssembly().CodeBase

your developer project you'll have to put in config file or otherwise save it in some application settings.


WebClient wc = new WebClient();
byte[] bytes = wc.DownloadData("http://xyz.com/Image/1.jpg");
System.IO.File.WriteAllBytes("your_path+your_filename+fileextention", bytes);


这篇关于如何保存从WebClient方法下载的图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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