熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C# 制作以動畫的方式顯示圖像[2]

2013-11-13 10:59:33  來源: .NET編程 

   
  代碼: 

private void button_Click(object sender EventArgs e)
  {
  
  try
  {
  int width = thispictureBoxWidth; //圖像寬度
  int height = thispictureBoxHeight; //圖像高度
  Graphics g = thispanelCreateGraphics();
  gClear(ColorGray);
  Bitmap bitmap = new Bitmap(width height);
  int x = ;
  while (x <= height / )
  {
  for (int i = ; i <= width ; i++)
  {
  bitmapSetPixel(i x MyBitmapGetPixel(i x));
  }
  for (int i = ; i <= width ; i++)
  {
  bitmapSetPixel(i height x MyBitmapGetPixel(i height x ));
  }
  x++;
  thispanelRefresh();
  gDrawImage (bitmap);
  SystemThreadingThreadSleep();
  }
  }
  catch (Exception ex)
  {
  MessageBoxShow(exMessage 信息提示);
  }
  }

  三 以四周擴散的方式顯示圖像 
  
  原理: 首先設置圖像顯示的位置 然後按高度和寬度的比例循環輸出 直到高度和寬度為原始大小 
  
  代碼: 

private void button_Click(object sender EventArgs e)
  {
  
  try
  {
  int width = thisMyBitmapWidth; //圖像寬度
  int height = thisMyBitmapHeight; //圖像高度
  //取得Graphics對象
  Graphics g = thispanelCreateGraphics();
  gClear(ColorGray); //初始為全灰色
  for (int i = ; i <= width / ; i++)
  {
  int j = ConvertToInt (i*(ConvertToSingle(height) / ConvertToSingle(width)));
  Rectangle DestRect = new Rectangle(width / i height/j * i *j);
  Rectangle SrcRect = new Rectangle( MyBitmapWidth MyBitmapHeight);
  gDrawImage(MyBitmap DestRect SrcRect GraphicsUnitPixel);
  SystemThreadingThreadSleep();
  }
  }
  catch (Exception ex)
  {
  MessageBoxShow(exMessage 信息提示);
  }
  } 

  

[]  []  []  []  []  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/14937.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.