问题描述
你好,
请帮帮我。
我正在尝试从网站下载图像。我尝试了很多方法,总是可以将图像下载到我的计算机上,但是当我尝试打开图像时,我得到了以下错误:"无法打开此图片,因为文件似乎已损坏,损坏了
或太大了"
我使用了其他时间使用过的代码总是很好,我不知道会发生什么。
这是图片的链接:
http://www.orange-book.com/detail/obwfk53010/contents_images/article_cd: MS2MSD0330 2080 / is_not_main:1 / imageno:2
  ; using(System.Net.WebClient client = new System.Net.WebClient())
{
client.DownloadFile(new Uri(" http:/ /www.orange-book.com/detail/obwfk53010/contents_images/article_cd:MS2MSD0330%202080/is_not_main:1/imageno:2"),@" c:\ temp\image251.jpg");
}
(OR)
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(" http://www.orange-book.com/细节/ obwfk53010 / contents_images / article_cd:MS2MSD0330                    2080 / is_not_main:1 / imageno:2");
          HttpWebResponse response =(HttpWebResponse)request.GetResponse();
          if((response.StatusCode == HttpStatusCode.OK ||
response.StatusCode == HttpStatusCode.Moved ||
response.StatusCode == HttpStatusCode.Redirect))
          {
         
             使用(Stream inputStream = response.GetResponseStream())
              using(Stream outputStream = File.OpenWrite(@" c:\ temp \ image15.png")))
              {
                  byte [] buffer = new byte [4096];
                  int bytesRead;
                 你是
                  {
                      bytesRead = inputStream.Read(buffer,0,buffer.Length);
                      outputStream.Write(buffer,0,bytesRead);
                  } while(bytesRead!= 0);
              }¥b $ b           }
hello,
please help me.
i'm tryin gto download an image from a website. I tried a lot of methods and always I can download the image ti my computer, but when I try to open the image i get the folllowing error: "Can't open this icture because the file appears to damaged, corrupted or is too large"
I used a code that I used other times and allways worked fine, I don't know what happens.
this is the link to the image:
http://www.orange-book.com/detail/obwfk53010/contents_images/article_cd:MS2MSD0330 2080/is_not_main:1/imageno:2
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.DownloadFile(new Uri("http://www.orange-book.com/detail/obwfk53010/contents_images/article_cd:MS2MSD0330%202080/is_not_main:1/imageno:2"), @"c:\temp\image251.jpg");
}
(OR)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.orange-book.com/detail/obwfk53010/contents_images/article_cd:MS2MSD0330 2080/is_not_main:1/imageno:2");HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if ((response.StatusCode == HttpStatusCode.OK ||
response.StatusCode == HttpStatusCode.Moved ||
response.StatusCode == HttpStatusCode.Redirect))
{
using (Stream inputStream = response.GetResponseStream())
using (Stream outputStream = File.OpenWrite(@"c:\temp\image15.png"))
{
byte[] buffer = new byte[4096];
int bytesRead;
do
{
bytesRead = inputStream.Read(buffer, 0, buffer.Length);
outputStream.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
}
}
这篇关于无法从网上下载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!