い私のケーリングされたイメージを含クライアントまで、フルのC#

StackOverflow https://stackoverflow.com/questions/194659

  •  10-07-2019
  •  | 
  •  

質問

これは奇質問してしまっているんですけど規模の私の画像をクライアントまで、フルのC#が必要ですのドット絵のない含.のようにザイナーで展開図を制作する。

私は映像の抗エイリアスはデフォルトクライアントまで、フルのC#または他のいかんです。

ったので色々と遊んでいて、 Graphics.InterpolationMode な幸運である。を使用しているビットマップオブジェクトを保持する画像が建設されているように:

// A custom control holds the image
this.m_ZoomPanPicBox.Image = new Bitmap(szImagePath);

簡単なsynapsisのカスタムの制御:

class ZoomPanPicBox : ScrollableControl
{
    Image m_image;
    float m_zoom = 1.0f;
    InterpolationMode m_interpolationMode;
    ...
    ////////////////////////////////////////////////////////
    public ZoomPanPicBox()
    {
        //Double buffer the control
        this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

        this.AutoScroll=true;
    }
    ////////////////////////////////////////////////////////
    protected override void OnPaint(PaintEventArgs e)
    {
        //if no image, don't bother
        if(m_image==null)
        {
            base.OnPaintBackground(e);
            return;
        }

        //Set up a zoom matrix
        Matrix mx = new Matrix(m_zoom,0,0,m_zoom,0,0);

        //now translate the matrix into position for the scrollbars
        mx.Translate(this.AutoScrollPosition.X / m_zoom, this.AutoScrollPosition.Y / m_zoom);

        //use the transform
        e.Graphics.Transform = mx;

        //and the desired interpolation mode
        e.Graphics.InterpolationMode = m_interpolationMode;

        //Draw the image ignoring the images resolution settings.
        e.Graphics.DrawImage(m_image,new Rectangle(0,0,this.m_image.Width,this.m_image.Height),0,0,m_image.Width, m_image.Height,GraphicsUnit.Pixel);

        base.OnPaint(e);
    }

そのアイデア?感謝。

役に立ちましたか?

解決

実は、そうかもしれませんとInterpolationMode、 のドキュメントと言う.で設定しInterpolationMode.NearestNeighbor.コードでサンプルなセットm_interpolationMode.

他のヒント

まあ、あなたは自分でスケールを実装し、単純な線形補間を行うことができます(つまり、バイキュービックのような隣接平均化を行いません)...それらは見栄えがよく、ブロック状に見えます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top