以前の回答は、よく意図されていましたが、部分的にしか正しくありませんでした。
何が正しかったですか?PictureBoxはInterpolationModeを公開しません。
何がオフベースでしたか?
1)そのプロパティは、画像ボックスから、その親で、または派生クラスのオーバーライドを介して、Paintイベントで簡単に設定できます。。。どちらの方法でも機能し、どちらも同じように簡単です。ただし、SmoothingModeが設定されていない限り、InterpolationModeは無視されます。SmoothingModeをSmoothingMode.AnitAliasに設定しないと、アンチエイリアシングは取得されません。
2)PictureBoxの機能を使用することに明確に関心を示したときにパネルを使用することは、間違った方向です。これらのプロパティを明示的にコーディングせずに、画像を直接読み込んだり、保存したり、割り当てたりすることはできません。。。なぜ車輪の再発明をするのですか? PictureBoxから派生することにより、それらすべてを無料で入手できます。
私があなたのために一生懸命働いて、このメッセージを書くよりも時間がかからなかったので、 ニュースはさらに良くなりました。
どちらもPictureBoxから派生した2つのバージョンを提供しました。1つ目は、常に可能な限り最高品質のレンダリングを使用する簡単な例です。これは最も遅いレンダリングでもあります。2つ目は、派生クラスのプロパティを介して誰でもさまざまなレンダリングパラメータを設定できるようにするクラスです。一度設定すると、これらはOnPaintオーバーライドで使用されます。
public class HighQualitySmoothPictureBox : PictureBox
{
protected override void OnPaint(PaintEventArgs pe)
{
// This is the only line needed for anti-aliasing to be turned on.
pe.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// the next two lines of code (not comments) are needed to get the highest
// possible quiality of anti-aliasing. Remove them if you want the image to render faster.
pe.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
pe.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
// this line is needed for .net to draw the contents.
base.OnPaint(pe);
}
}
..。
public class ConfigurableQualityPictureBox : PictureBox
{
// Note: the use of the "?" indicates the value type is "nullable."
// If the property is unset, it doesn't have a value, and therefore isn't
// used when the OnPaint method executes.
System.Drawing.Drawing2D.SmoothingMode? smoothingMode;
System.Drawing.Drawing2D.CompositingQuality? compositingQuality;
System.Drawing.Drawing2D.InterpolationMode? interpolationMode;
public System.Drawing.Drawing2D.SmoothingMode? SmoothingMode
{
get { return smoothingMode; }
set { smoothingMode = value; }
}
public System.Drawing.Drawing2D.CompositingQuality? CompositingQuality
{
get { return compositingQuality; }
set { compositingQuality = value; }
}
public System.Drawing.Drawing2D.InterpolationMode? InterpolationMode
{
get { return interpolationMode; }
set { interpolationMode = value; }
}
protected override void OnPaint(PaintEventArgs pe)
{
if (smoothingMode.HasValue)
pe.Graphics.SmoothingMode = smoothingMode.Value;
if (compositingQuality.HasValue)
pe.Graphics.CompositingQuality = compositingQuality.Value;
if (interpolationMode.HasValue)
pe.Graphics.InterpolationMode = interpolationMode.Value;
// this line is needed for .net to draw the contents.
base.OnPaint(pe);
}
}