我通过下面的方法下载图片:
string fileName = "test.bmp";
string url = "http://localhost/emsmanage/Web/AD/ADFiles/" + fileName;
string locFolder = @"E:/Image";
string path = locFolder + "/" + fileName;
HttpWebRequest request = null;
HttpWebResponse response = null;

//发送请求
request=(HttpWebRequest)WebRequest.Create(url);
//接收信息
response=(HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); BinaryReader br = new BinaryReader(s);
int length2 = Convert.ToInt32(response.ContentLength);
byte[] byteArr = new byte[length2];
s.Read(byteArr, 0, length2); if (File.Exists(path))
{
File.Delete(path);
} FileStream fs = File.Create(path);


fs.Write(byteArr, 0, length2);
fs.Close(); br.Close();为什么得到的图片与原来的图片不一样.(得到的图片为黑色,真正的图片为底色蓝色,上面有红字)

解决方案 »

  1.   

    用downloadFile应该可以吧~~~~
    string remoteUri = "http://www.contoso.com/library/homepage/images/";
    string fileName = "ms-banner.gif", myStringWebResource = null;
    // Create a new WebClient instance.
    WebClient myWebClient = new WebClient();
    // Concatenate the domain with the Web resource filename.
    myStringWebResource = remoteUri + fileName;
    Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
    // Download the Web resource and save it into the current filesystem folder.
    myWebClient.DownloadFile(myStringWebResource,fileName);        
    Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
    Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);
      

  2.   

    不行啊,规定要用HttpWebResponse
    问题会不会是出现在FileStream fs 上?
      

  3.   

    你用FC比较一下。如果一样的话。问题应该在IE对透明图片的处理上