私はその場で画像を作成し、それを 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 を返したい。解決策とは何ですか?これはどのように機能しますか?