1 /// <summary>
 2         /// 网络流转换为Byte数组
 3         /// </summary>
 4         /// <param name="stream"></param>
 5         /// <returns></returns>
 6         public static byte[] ReadFully(Stream stream)
 7         {
 8             byte[] buffer = new byte[128];
 9             using (MemoryStream ms = new MemoryStream())
10             {
11                 while (true)
12                 {
13                     int read = stream.Read(buffer, 0, buffer.Length);
14                     if (read <= 0)
15                         return ms.ToArray();
16                     ms.Write(buffer, 0, read);
17                 }
18             }
19         }
复制代码

 

复制代码
 1 /// <summary>
 2         /// 网络流转换为Byte数组
 3         /// </summary>
 4         /// <param name="stream"></param>
 5         /// <returns></returns>
 6         public static byte[] ReadFully(Stream stream)
 7         {
 8             byte[] img = null;
 9             int size = 1024;
10             int read = 0;
11             MemoryStream ms = new MemoryStream();
12             byte[] buffer = new byte[size];
13             do
14             {
15                 buffer = new byte[size];
16                 read = resst.Read(buffer, 0, size);
17                 ms.Write(buffer, 0, read);
18             } while (read > 0);
19             img = ms.ToArray();      
20         }