gpt4 book ai didi

c# - 如何从 HttpPostedFile 创建字节数组

转载 作者:IT王子 更新时间:2023-10-29 03:31:36 31 4
gpt4 key购买 nike

我正在使用具有 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com