29

ボックスはスプリッターでサイズ変更できるため、私は StretchImage を使用しています。デフォルトはある種の滑らかなバイリニア フィルタリングのように見え、画像がぼやけてモアレ パターンが発生します。

4

4 に答える 4

37

この機能も必要でした。PictureBox を継承しOnPaint、補間モードを設定できるようにプロパティをオーバーライドして追加するクラスを作成しました。

using System.Drawing.Drawing2D;
using System.Windows.Forms;

/// <summary>
/// Inherits from PictureBox; adds Interpolation Mode Setting
/// </summary>
public class PictureBoxWithInterpolationMode : PictureBox
{
    public InterpolationMode InterpolationMode { get; set; }

    protected override void OnPaint(PaintEventArgs paintEventArgs)
    {
        paintEventArgs.Graphics.InterpolationMode = InterpolationMode;
        base.OnPaint(paintEventArgs);
    }
}
于 2012-11-20T23:40:08.863 に答える
5

ImageクラスとDrawImage関数を使用して手動でサイズ変更を行い、PictureBoxのサイズ変更イベントに応答する必要があると思われます。

于 2008-08-26T23:41:19.593 に答える
3

私はMSDN検索を行いましたが、これに関する記事があります。これはあまり詳細ではありませんが、paintイベントを使用する必要があることを概説しています。

http://msdn.microsoft.com/en-us/library/k0fsyd4e.aspx

この機能を使用するために、一般的に利用可能な画像ズームの例を編集しました。以下を参照してください。

編集元:http ://www.dotnetcurry.com/ShowArticle.aspx?ID = 196&AspxAutoDetectCookieSupport = 1

お役に立てれば

    private void Form1_Load(object sender, EventArgs e)
    {
        // set image location
        imgOriginal = new Bitmap(Image.FromFile(@"C:\images\TestImage.bmp"));
        picBox.Image = imgOriginal;

        // set Picture Box Attributes
        picBox.SizeMode = PictureBoxSizeMode.StretchImage;

        // set Slider Attributes
        zoomSlider.Minimum = 1;
        zoomSlider.Maximum = 5;
        zoomSlider.SmallChange = 1;
        zoomSlider.LargeChange = 1;
        zoomSlider.UseWaitCursor = false;

        SetPictureBoxSize();

        // reduce flickering
        this.DoubleBuffered = true;
    }

    // picturebox size changed triggers paint event
    private void SetPictureBoxSize()
    {
        Size s = new Size(Convert.ToInt32(imgOriginal.Width * zoomSlider.Value), Convert.ToInt32(imgOriginal.Height * zoomSlider.Value));
        picBox.Size = s;
    }


    // looks for user trackbar changes
    private void trackBar1_Scroll(object sender, EventArgs e)
    {
        if (zoomSlider.Value > 0)
        {
            SetPictureBoxSize();
        }
    }

    // redraws image using nearest neighbour resampling
    private void picBox_Paint_1(object sender, PaintEventArgs e)
    {
        e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
        e.Graphics.DrawImage(
           imgOriginal,
            new Rectangle(0, 0, picBox.Width, picBox.Height),
            // destination rectangle 
            0,
            0,           // upper-left corner of source rectangle
            imgOriginal.Width,       // width of source rectangle
            imgOriginal.Height,      // height of source rectangle
            GraphicsUnit.Pixel);
    }
于 2011-02-22T14:21:38.960 に答える
-4

.netで画像のサイズを変更する場合、System.Drawing.Drawing2D.InterpolationModeは次のサイズ変更方法を提供します。

  • バイキュービック
  • バイリニア
  • 高い
  • HighQualityBicubic
  • HighQualityBilinear
  • 低い
  • NearestNeighbor
  • デフォルト
于 2008-08-26T23:47:17.583 に答える