私はmvc4アプリケーションを作成し、次のようなpngファイルを出力するコントローラーを持っています:
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Web.Mvc;
using Foobar.Classes;
namespace Foobar.Controllers
{
public class ImageController : Controller
{
public ActionResult Index(Label[] labels)
{
var bmp = new Bitmap(400, 300);
var pen = new Pen(Color.Black);
var font = new Font("arial", 20);
var g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
if (labels != null)
{
g.DrawString("" + labels.Length, font, pen.Brush, 20, 20);
if (labels.Length > 0)
{
g.DrawString("" + labels[0].label, font, pen.Brush, 20, 40);
}
}
var stream = new MemoryStream();
bmp.Save(stream, ImageFormat.Png);
stream.Position = 0;
return File(stream, "image/png");
}
}
}
Label クラスは次のようになります。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Foobar.Classes
{
public class Label
{
public string label { get; set; }
public int fontsize { get; set; }
}
}
これをURLに含めてコントローラーを実行すると:
http://localhost:57775/image?labels[0][label]=Text+rad+1&labels[0][fontsize]=5&labels[1][fontsize]=5&labels[2][fontsize]=5
適切な量のラベルを取得したため、画像には 3 が表示されます。しかし、Label のインスタンスは、そのデータ メンバーが入力されません。また、(プロパティではなく) プレーン変数を使用してこれを実行しようとしました。
それらが入力されている場合、画像には実際には「3」と「Text rad 1」が表示されます。
では、プロパティを正しく設定するには、クラス「ラベル」に何を入れればよいでしょうか? ある種の注釈が必要ですか?
これについてはどこで読めますか?