黑马程序员技术交流社区

标题: C#panel控件加载超大图片,鼠标mousemove时,图像卡顿严重,求指点 [打印本页]

作者: 王志平    时间: 2013-4-26 20:47
标题: C#panel控件加载超大图片,鼠标mousemove时,图像卡顿严重,求指点
暂未加载到内存中处理,猜测不是这个原因,已开双缓冲DoubleBuffered = true;panel是自定义的usercontrol;测试1000*1000范围内,浏览拖动图像无卡顿,千位像素级别以上越大卡顿越明显,原因大致清楚:每次移动时都是针对该图片偏移量移动,所以图片越大移动越困难,想保持图片不动,移动图片时相对移动panel相对图片的坐标来浏览图像,只是猜测,求指点,小弟新人一个,第一次发帖,如有不对请指出!
附代码:
  1. public Pic_Position_Move()
  2.         {
  3.             InitializeComponent();
  4.         }
  5.         Point offset = new Point(0, 0);
  6.         Point p;
  7.         Bitmap fileBitmap;
  8.         private void btnLoad_Click(object sender, EventArgs e)
  9.         {
  10.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  11.             {
  12.                 fileBitmap = new Bitmap(openFileDialog1.FileName);
  13.                 offset = new Point(0, 0);
  14.                 panShow.Invalidate();
  15.             }
  16.         }

  17.         private void panShow_Paint(object sender, PaintEventArgs e)
  18.         {
  19.             if (fileBitmap != null)
  20.                 e.Graphics.DrawImage(fileBitmap, offset);
  21.         }

  22.         private void panShow_MouseMove(object sender, MouseEventArgs e)
  23.         {
  24.             if (e.Button == MouseButtons.Left && fileBitmap != null)
  25.             {
  26.                 offset.Offset(e.X - p.X, e.Y - p.Y);
  27.                 p = e.Location;
  28.                 panShow.Invalidate();
  29.             }
  30.         }
  31.         private void panShow_MouseDown(object sender, MouseEventArgs e)
  32.         {
  33.             if (e.Button == MouseButtons.Left && fileBitmap != null)
  34.             {
  35.                 panShow.Cursor = Cursors.Hand;
  36.                 p = e.Location;
  37.                 panShow.Invalidate();
  38.             }
  39.         }

  40.         private void panShow_MouseUp(object sender, MouseEventArgs e)
  41.         {
  42.             panShow.Cursor = Cursors.Default;           
  43.             panShow.Invalidate();
  44.         }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2