作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用具有 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);
最佳答案
使用 BinaryReader 对象从流中返回字节数组,如:
byte[] fileData = null;
using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
{
fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
}
关于c# - 如何从 HttpPostedFile 创建字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/359894/
我是一名优秀的程序员,十分优秀!