ARGB 32 ピクセル形式のビットマップを取得して、内接楕円内のコンテンツが残り、楕円外のものはすべて ARGB(0,0,0,0) に変わるようにクリップしたいと思います。GetPixel と SetPixel といくつかの三角法を使用してプログラムで実行して、どのピクセルが範囲外であるかを把握できますが、それを行うためのより優れた組み込みの方法があると思います。
何か案は?
ARGB 32 ピクセル形式のビットマップを取得して、内接楕円内のコンテンツが残り、楕円外のものはすべて ARGB(0,0,0,0) に変わるようにクリップしたいと思います。GetPixel と SetPixel といくつかの三角法を使用してプログラムで実行して、どのピクセルが範囲外であるかを把握できますが、それを行うためのより優れた組み込みの方法があると思います。
何か案は?
地域の部分を指摘してくれた Alessandro D'Andria に感謝します - 私は残りを理解しました:
public Bitmap Rasterize()
{
Bitmap ringBmp = new Bitmap(width: _size.Width, height: _size.Height, format: PixelFormat.Format32bppArgb);
//Create an appropriate region from the inscribed ellipse
Drawing2D.GraphicsPath graphicsEllipsePath = new Drawing2D.GraphicsPath();
graphicsEllipsePath.AddEllipse(0, 0, _size.Width, _size.Height);
Region ellipseRegion = new Region(graphicsEllipsePath);
//Create a graphics object from our new bitmap
Graphics gfx = Graphics.FromImage(ringBmp);
//Draw a resized version of our image to our new bitmap while using the highest quality interpolation and within the defined ellipse region
gfx.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor;
gfx.SmoothingMode = Drawing2D.SmoothingMode.HighQuality;
gfx.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality;
gfx.PageUnit = GraphicsUnit.Pixel;
gfx.Clear(Color.Transparent);
gfx.Clip = ellipseRegion;
gfx.DrawImage(image: _image, rect: new Rectangle(0, 0, _size.Width, _size.Height));
//Dispose our graphics
gfx.Dispose();
//return the resultant bitmap
return ringBmp;
}
PixelOffsetMode を HighQuality に設定することは明らかに非常に重要です。そうしないと、DrawImage メソッドが結果の画像の一部を切り取ってしまうからです。