将图片Stream
转换为byre[]
始终返回null
这是代码:
...
Stream Stream = responce.GetResponseStream();
StreamReader reader = new StreamReader(Stream);
string reader_str = reader.ReadToEnd();
byte[] bytes = ReadFully(Stream); //I don't know why bytes is NULL
public static byte[] ReadFully(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
Stream是一张png图片!
如何保存下面的图像?
MemoryStream ms = new MemoryStream();
Stream.CopyTo(ms);
Image img = Image.FromStream(ms); //Parameter is not valid ERROR
img.Save(image_path, ImageFormat.Jpeg);
答案 0 :(得分:1)
您已经通过reader.ReadToEnd()
;读取了结束的信息流。在再次从流中读取之前,您需要Seek()
到开头。
reader_str
的任何原因?