日期:2014-05-18  浏览次数:20537 次

怎么取不到传说中的图片?
下面的程序是从网页中抓取图片,然后用数据流读取下来,保存在服务器上,但是
显示的是乱码,生成的图片也是乱码,高手来解决下哈

byte[]   bytes   =   new   byte[90000];

                HttpWebRequest   vHttpWebRequest   =   (HttpWebRequest)WebRequest.Create( "http://zi.csdn.net/2007.06/now120x60.gif ");
                HttpWebResponse   vHttpWebResponse   =   (HttpWebResponse)vHttpWebRequest.GetResponse();
                BinaryReader   vBinaryReader   =   new   BinaryReader(vHttpWebResponse.GetResponseStream());

                vBinaryReader.Read(bytes,   0,   90000);


                byte[]   photo   =   vBinaryReader.ReadBytes(90000);

                vHttpWebResponse.Close();

                  //for   (int   i   =   0;   i   <   photo.Length;i++   )
                    //TextBox1.Text   +=   photo[i].ToString();

                string   strPath   =   "wangwu.JPG ";
                string   strPhotoPath   =   Server.MapPath(strPath);
                //保存图片文件
                BinaryWriter   bw   =   new   BinaryWriter(File.Open(strPhotoPath,   FileMode.OpenOrCreate));
                bw.Write(photo);
                bw.Close();


------解决方案--------------------

WebClient client = new WebClient();
client.DownloadFile(imgurl, "E:\wangwu.jpg ");
client.Dispose();
------解决方案--------------------
for(int i=0;i <photo.count;i++)
{
bw.Write(photo[i]);
}

O_O.....O_O
------解决方案--------------------
绝对不是乱码——

System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile( "http://zi.csdn.net/2007.06/now120x60.gif ", "E:\now120x60.gif ");
client.Dispose();