【发布时间】:2010-09-26 11:17:47
【问题描述】:
我正在使用具有 FromBinary 方法的图像组件。想知道如何将输入流转换为字节数组
HttpPostedFile file = context.Request.Files[0];
byte[] buffer = new byte[file.ContentLength];
file.InputStream.Read(buffer, 0, file.ContentLength);
ImageElement image = ImageElement.FromBinary(byteArray);
【问题讨论】:
-
我们如何在另一个 .aspx 页面中发布文件?
-
这行 file.InputStream.Read(buffer, 0, file.ContentLength); 不是用输入流中的字节填充缓冲区吗?为什么我们应该使用@Wolfwyrd 在下面的答案中提到的 BinaryReader.ReadBytes(...) ? ImageElement.FromBinary(buffer); 不能解决问题吗?