首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 圖片動畫顯示技巧(三):四周擴散與分塊顯示

     編輯:關於C語言

四周擴散效果


private void btnExpand_Click(object sender, EventArgs e)
{
    int w = MyBitmap.Width, h = MyBitmap.Height;
    Graphics g = panel1.CreateGraphics();
    g.Clear(Color.Gray);

    for (int i = 0; i <= w / 2; i++)
    {
        int j = (int)(i * (float)h / w); // 保持長寬比
        var dest = new Rectangle(w/2 - i, h/2 - j, 2*i, 2*j);
        var src = new Rectangle(0, 0, w, h);
        g.DrawImage(MyBitmap, dest, src, GraphicsUnit.Pixel);
        Thread.Sleep(10);
    }
}

從中心點向四周按比例擴大繪製矩形,產生放大動畫。

分塊顯示效果


private void btnBlock_Click(object sender, EventArgs e)
{
    Graphics g = panel1.CreateGraphics();
    g.Clear(Color.White);
    int w = MyBitmap.Width, h = MyBitmap.Height;

    // 切割 4 區塊
    var blocks = new RectangleF[]
    {
        new RectangleF(0, 0, w/2, h/2),
        new RectangleF(w/2, 0, w/2, h/2),
        new RectangleF(0, h/2, w/2, h/2),
        new RectangleF(w/2, h/2, w/2, h/2)
    };

    var pieces = blocks.Select(b => MyBitmap.Clone(b, PixelFormat.DontCare)).ToArray();

    g.DrawImage(pieces[0], 0, 0); Thread.Sleep(1000);
    g.DrawImage(pieces[1], w/2, 0); Thread.Sleep(1000);
    g.DrawImage(pieces[3], w/2, h/2); Thread.Sleep(1000);
    g.DrawImage(pieces[2], 0, h/2);
}

將圖片四等分,依序繪製每塊,間隔 1 秒,產生拼圖組裝效果。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved