方法 : 拡大/縮小効果を作成します。

[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]

2 番目の最初の拡大センター セクションを格納、同じサイズの 2 つのビットマップとズーム効果をシミュレートするプログラム例を次に示します。

使用例

                        ' Define bmp and bmpZoom as
                        ' global Bitmap variables for your form.
                        
' Call CreateBitmap and then DefineZoom
                        ' from your form's consructor.
                        Sub CreateBitmap()
    bmp = New Bitmap(75, 75)
    Dim g As Graphics = Graphics.FromImage(bmp)

    Dim BlueBrush AsNew SolidBrush(Color.Blue)
    Dim RedBrush AsNew SolidBrush(Color.Red)

    Dim OuterRect AsNew Rectangle(0, 0, 200, 200)
    g.FillRectangle(BlueBrush, OuterRect)

    Dim InnerRect AsNew Rectangle(25, 25, 25, 25)
    g.FillRectangle(RedBrush, InnerRect)

    g.Dispose()
EndSubSub ZoomImage()
    bmpZoom = New Bitmap(bmp.Width, bmp.Height)
    Dim g As Graphics = Graphics.FromImage(bmpZoom)

    Dim srcRect AsNew Rectangle(CInt(bmp.Width / 4), CInt(bmp.Height / 4), _
        CInt(bmp.Width / 2), CInt(bmp.Height / 2))
    Dim dstRect AsNew Rectangle(0, 0, bmpZoom.Width, bmpZoom.Height)
    g.DrawImage(bmp, dstRect, srcRect, GraphicsUnit.Pixel)
EndSubProtectedOverridesSub OnPaint(ByVal e As PaintEventArgs)
    e.Graphics.DrawImage(bmp, 0, 0)
    e.Graphics.DrawImage(bmpZoom, 125, 0)

    bmp.Dispose()
    bmpZoom.Dispose()
    MyBase.OnPaint(e)
EndSub
                        // Define bmp and bmpZoom as
                        // global Bitmap variables for your form.
                        // Call CreateBitmap and then DefineZoom
                        // from your form's consructor.
                        void CreateBitmap()
{
    bmp = new Bitmap(75, 75);
    Graphics g = Graphics.FromImage(bmp);
    SolidBrush BlueBrush = new SolidBrush(Color.Blue);
    SolidBrush RedBrush = new SolidBrush(Color.Red);
    Rectangle OuterRect = new Rectangle(0, 0, 200, 200);
    g.FillRectangle(BlueBrush, OuterRect);
    Rectangle InnerRect = new Rectangle(25, 25, 25, 25);
    g.FillRectangle(RedBrush, InnerRect);
    g.Dispose();
}

   privatevoid ZoomImage()
    {
        bmpZoom = new Bitmap(bmp.Width, bmp.Height);
        Graphics g = Graphics.FromImage(bmpZoom);
        int new4W = bmp.Width / 4;
        int new4H = bmp.Height / 4;
        int new2W = bmp.Width / 2;
        int new2H = bmp.Height / 2;
        Rectangle srcRect = new Rectangle(new4W, new4H, new2W, new2H);
        Rectangle dstRect = new Rectangle(0, 0, bmpZoom.Width, bmpZoom.Height);
        g.DrawImage(bmp, dstRect, srcRect, GraphicsUnit.Pixel);
    }

    protectedoverridevoid OnPaint(PaintEventArgs e)
    {
        e.Graphics.DrawImage(bmp, 0, 0);
        e.Graphics.DrawImage(bmpZoom, 125, 0);
        base.OnPaint(e);
    }

コードのコンパイル方法

この例では、次の名前空間への参照が必要です。

参照

概念

.NET コンパクトなフレームワーク方法を説明したトピックの検索

その他の技術情報

グラフィックスと、.NET での描画の最適化フレームワーク