如何从HttpPostedFile创建字节数组 [英] How to create byte array from HttpPostedFile
本文介绍了如何从HttpPostedFile创建字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我使用具有FromBinary方法的图像组件。想知道如何将我的输入流成字节数组
HttpPostedFile文件= context.Request.Files [0];
字节[]缓冲区=新的字节[file.ContentLength]
file.InputStream.Read(缓冲液,0,file.ContentLength);ImageElement图像= ImageElement.FromBinary(字节阵列);
解决方案
使用一个BinaryReader对象从流像返回一个字节数组:
字节[] FILEDATA = NULL;
使用(VAR binaryReader =新BinaryReader(Request.Files [0] .InputStream))
{
FILEDATA = binaryReader.ReadBytes(Request.Files [0] .ContentLength);
}
Hi I'm using an image component that has a FromBinary method. Wondering how do i convert my input stream into a byte array
HttpPostedFile file = context.Request.Files[0];
byte[] buffer = new byte[file.ContentLength];
file.InputStream.Read(buffer, 0, file.ContentLength);
ImageElement image = ImageElement.FromBinary(byteArray);
解决方案
Use a BinaryReader object to return a byte array from the stream like:
byte[] fileData = null;
using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
{
fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
}
这篇关于如何从HttpPostedFile创建字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文