说明:
由于是以动画方式显示图像,这里没办法直接贴静态截图,因此决定给园友开源,将所有的可运行代码附在案例后面,由于所有的动画处理图像的对象放在都picturebox控件中,同时定义的类都大同小异,因此这里先把下面案例中要用到的所有类及装载图像的代码给大家,运行时用这里的代码加下面任意一个实例的代码即可运行程序!
 private bitmap sourcebitmap; 
  private bitmap mybitmap; 
  private void button2_click(object sender, eventargs e) 
  { 
  //打开图像文件 
  openfiledialog openfiledialog = new openfiledialog(); 
  openfiledialog.filter = "图像文件(jpeg, gif, bmp, etc.) 
  |*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png| jpeg 图像文件(*.jpg;*.jpeg) 
  |*.jpg;*.jpeg |gif 图像文件(*.gif)|*.gif |bmp图像文件(*.bmp)|*.bmp 
  |tiff图像文件(*.tif;*.tiff)|*.tif;*.tiff|png图像文件(*.png)| *.png |所有文件(*.*)|*.*"; 
  if (openfiledialog.showdialog() == dialogresult.ok) 
  { 
  //得到原始大小的图像 
  sourcebitmap = new bitmap(openfiledialog.filename); 
  //得到缩放后的图像 
  mybitmap = new bitmap(sourcebitmap, this.picturebox1.width, this.picturebox1.height); 
  this.picturebox1.image = mybitmap; 
  } 
  } 
 
一、以上下反转的方式显示图像. 
原理:计算图像位置和高度后以高度的一半为轴进行对换上下半边的图像。
代码:
 private void button1_click(object sender, eventargs e) 
  { 
   
  try 
  { 
  int width = this.mybitmap.width; //图像宽度 
  int height = this.mybitmap.height; //图像高度 
  graphics g = this.panel1.creategraphics(); 
  g.clear(color.gray); 
  for (int i = -width / 2; i <= width / 2; i++) 
  { 
  g.clear(color.gray); 
  int j = convert.toint32(i * (convert.tosingle(height) / convert.tosingle(width))); 
  rectangle destrect = new rectangle(0, height / 2 -j, width, 2 * j); 
  rectangle srcrect = new rectangle(0, 0, mybitmap.width, mybitmap.height); 
  g.drawimage(mybitmap, destrect, srcrect, graphicsunit.pixel); 
  system.threading.thread.sleep(10); 
  } 
  } 
  catch (exception ex) 
  { 
  messagebox.show(ex.message, "信息提示"); 
  } 
  } 
 
二、以上下对接的方式显示图像
原理:首先将图像分为上下两部分, 然后分别显示。
代码:
  private void button1_click(object sender, eventargs e) 
  { 
   
  try 
  { 
  int width = this.picturebox1.width; //图像宽度 
  int height = this.picturebox1.height; //图像高度 
  graphics g = this.panel1.creategraphics(); 
  g.clear(color.gray); 
  bitmap bitmap = new bitmap(width, height); 
  int x = 0; 
  while (x <= height / 2) 
  { 
  for (int i = 0; i <= width - 1; i++) 
  { 
  bitmap.setpixel(i, x, mybitmap.getpixel(i, x)); 
  } 
  for (int i = 0; i <= width - 1; i++) 
  { 
  bitmap.setpixel(i, height - x - 1, mybitmap.getpixel(i, height - x - 1)); 
  } 
  x++; 
  this.panel1.refresh(); 
  g.drawimage (bitmap,0,0); 
  system.threading.thread.sleep(10); 
  } 
  } 
  catch (exception ex) 
  { 
  messagebox.show(ex.message, "信息提示"); 
  } 
  } 
 
三、以四周扩散的方式显示图像
原理:首先设置图像显示的位置, 然后按高度和宽度的比例循环输出, 直到高度和宽度为原始大小。
代码:
private void button1_click(object sender, eventargs e) 
  { 
   try 
  { 
  int width = this.mybitmap.width; //图像宽度 
  int height = this.mybitmap.height; //图像高度 
  //取得graphics对象 
  graphics g = this.panel1.creategraphics(); 
  g.clear(color.gray); //初始为全灰色 
  for (int i = 0; i <= width / 2; i++) 
  { 
  int j = convert.toint32 (i*(convert.tosingle(height) / convert.tosingle(width))); 
  rectangle destrect = new rectangle(width / 2 - i, height/2-j, 2 * i, 2*j); 
  rectangle srcrect = new rectangle(0, 0, mybitmap.width, mybitmap.height); 
  g.drawimage(mybitmap, destrect, srcrect, graphicsunit.pixel); 
  system.threading.thread.sleep(10); 
  } 
  } 
  catch (exception ex) 
  { 
  messagebox.show(ex.message, "信息提示"); 
  } 
  }