gpt4 book ai didi

c# - 我应该如何从 Controller 操作 c# asp.net-mvc-2 返回图像?

转载 作者:数据小太阳 更新时间:2023-10-29 06:03:35 24 4
gpt4 key购买 nike

我正在从 byte[] 构建图像,如下所示。

public FileContentResult GetEmployeeImage(int empId)
{
MemoryStream ms = new MemoryStream(byteArray);
Image returnImage = Image.FromStream(ms);
return returnImage;//How should i return this image to be consumed by javascript.
}

我想通过 Controller 操作方法将此图像返回给浏览器,以便它可以被我的 javascript 代码使用并显示在浏览器中。我应该怎么做?

最佳答案

您不需要创建图像对象;你只想返回原始数据。
浏览器会将原始数据读取到图像中。

return File(byteArray, "image/png");

显然,您需要传递正确的内容类型,具体取决于字节数组中的图像格式。

关于c# - 我应该如何从 Controller 操作 c# asp.net-mvc-2 返回图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5953045/

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