0

我正在尝试通过获取图像HttpWebRequest并以获胜形式显示它imagebox。通过 Fiddler ImageView 选项卡跟踪请求时,我可以看到可以正确看到图像,但是在读取流时出现Stream was not readable错误

Image img = Image.FromStream(stream). 

我错过了什么?

HttpWebRequest req =  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("[URL here]");
HttpWebResponse response = (HttpWebResponse)req.GetResponse();    
Stream stream = response.GetResponseStream();

Image img = Image.FromStream(stream);   // ERROR occurs here

stream.Close();
4

1 回答 1

0

经过一番挖掘,在这里找到了答案C# gif Image to MemoryStream and back (loose animation)

HttpWebRequest req =  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("[URL here]");
HttpWebResponse response = (HttpWebResponse)req.GetResponse();    
Stream stream = response.GetResponseStream();

MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
memoryStream.Position = 0;
stream = memoryStream;
Image img = Image.FromStream(stream);   

stream.Close();
于 2013-09-26T10:54:43.477 回答