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

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

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


  try
  {
  int width = thisMyBitmapWidth; //圖像寬度
  int height = thisMyBitmapHeight; //圖像高度
  Graphics g = thispanelCreateGraphics();
  gClear(ColorGray); //初始為全灰色
  Bitmap bitmap = new Bitmap(width height);
  int x = ;
  while (x <= width / )
  {
  for (int i = ; i <= height ; i++)
  {
  bitmapSetPixel(x i MyBitmapGetPixel(x i));
  }
  for (int i = ; i <= height ; i++)
  {
  bitmapSetPixel(width x i
  MyBitmapGetPixel(width x i));
  }
  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 g = thispanelCreateGraphics();
  gClear(ColorGray); //初始為全灰色
  for (int j = height / ; j <= height / ; j++)
  {
  gClear(ColorGray); //初始為全灰色
  int i = ConvertToInt(j * (ConvertToSingle(width) / ConvertToSingle(height)));
  Rectangle DestRect = new Rectangle(width / i * i height);
  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/14931.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.