2011-01-19 102 views

回答

3

如果您不想将文件直接保存到硬盘驱动器,可以将其下载到流中。例如

WebClient wc = new WebClient(); 
byte[] bytes = wc.DownloadData("http://www.example.com/image.jpg"); 
Bitmap b = new Bitmap(new MemoryStream(bytes)); 

如果再希望将它保存到你的硬盘,你可以调用Bitmap.Save()方法。例如

b.Save("bitmap.jpg"); 
0

我想你不能用WebBrowser静静地做到这一点。不要忘记,它最终是一个IE实例。你可以做的是:导航到IMAGEURL,然后调用ShowSaveAsDialog(),将显示一个另存为对话框,用户保存的图片:

WebBrowser wb = new WebBrowseR(); 
wb.Navigate("ImageURL"); 
wb.ShowSaveAsDialog(); 

更好的解决方案是使用Web客户端

来获得图像
System.Net.WebClient wc = new System.Net.WebClient(); 
wc.Credentials = new System.Net.NetworkCredential("username", "password"); //Authenticates to the website - Call it only if the image url needs authentication first 
wc.DownloadFile("imageURL", "downloadedImage.jpg"); //Downloads the imageURL to the local file downloadedImage.jpg 
相关问题