且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我应该如何从控制器动作c#asp.net-MVC-2返回图像?

更新时间:2023-02-25 16:41:48

您不需要创建图像对象;你只是想返回原始数据。结果
该浏览器将读取原始数据转换成图像。

You don't need to create an image object; you just want to return the raw data.
The browser will read the raw data into an image.

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

显然,你需要通过正确的内容类型,具体取决于图像格式是字节数组中

Obviously, you need to pass the correct content type, depending on what image format is in the byte array.