我正在使用具有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);
Wol*_*yrd 280
使用BinaryReader对象从流中返回字节数组,如:
byte[] fileData = null;
using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
{
    fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
}
小智 22
BinaryReader b = new BinaryReader(file.InputStream);
byte[] binData = b.ReadBytes(file.InputStream.Length);
第2行应替换为
byte[] binData = b.ReadBytes(file.ContentLength);
小智 11
如果您的文件InputStream.Position设置为流的末尾,它将无法工作.我的其他内容:
Stream stream = file.InputStream;
stream.Position = 0;
| 归档时间: | 
 | 
| 查看次数: | 116688 次 | 
| 最近记录: |