次のコードは、透明なビットマップを作成し、アンチエイリアシングを使用してその上に白い楕円を描画します。
using(var background = new Bitmap(500, 500))
using (var graphics = Graphics.FromImage(background))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.Clear(Color.Transparent);
graphics.DrawEllipse(new Pen(Color.White, 50), 250, 250, 150, 150);
background.Save("test.png", ImageFormat.Png);
}
私が見つけたバグは、楕円の端にあるアンチエイリアス処理されたピクセルが予期しない色になることです。RGB 値は (255,255,255) ではなく (254,254,254) です。GDI+ は透明を ARGB (0,255,255,255) として定義し、白を (255,255,255,255) として定義するため、ブレンド後に 254 が表示されるのはなぜですか?