标签:
前端请求代码
@{
ViewBag.Title = "View1";
}
<h2>返回图片</h2>
<hr/>
<img src="/Home/Returnimg">
后端返回图片代码
public ActionResult Returnimg()
{
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
g.FillRectangle(Brushes.Red, 1, 2, 100, 31);
g.DrawString("MVC返回图片", new Font("黑体", 19f), Brushes.Chocolate, new PointF(5f, 5f));
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
bmp.Dispose();
return File(ms.ToArray(), "image/jpeg");
}
标签:
原文地址:http://www.cnblogs.com/hyb121/p/5495232.html