我有一个控制器,它可以在飞行中制作图像并将其返回到ViewBag 中带有文本的视图,
public partial class TextController : Controller
{
public virtual ActionResult Index(bool noisy = true)
{
//image stream
FileContentResult img;
using (var mem = new MemoryStream())
using (var bmp = new Bitmap(130, 30))
using (var gfx = Graphics.FromImage((Image)bmp))
{
gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
gfx.SmoothingMode = SmoothingMode.AntiAlias;
gfx.FillRectangle(Brushes.White, new Rectangle(0, 0, bmp.Width, bmp.Height));
//add question
gfx.DrawString(text, new Font("Tahoma", 15), Brushes.Gray, 2, 3);
//render as Jpeg
bmp.Save(mem, System.Drawing.Imaging.ImageFormat.Jpeg);
img = File(mem.GetBuffer(), "image/Jpeg");
}
ViewBag.text = text;
return img;
}
我想从控制器返回一个图像和 ViewBag。什么是解决方案?我该怎么做?