像缩放一样调整Picturebox的大小,没有它造成的延迟

时间:2014-05-08 20:33:13

标签: c# zoom picturebox lag

我制作了一种可以制作线条和图标并且背面有图像的绘画程序。这张图片我想用滚轮缩放。

我发现的问题是当我调整它的大小时,我发现虽然100%的尺寸在移动图标时没有任何延迟,但是像200%一样放大,例如它是滞后的。

解决这个问题的智能和正确方法是什么?

代码:

@ Scroll wheel
previousWidth = previousWidth * 1.25;
previousHeight = previousHeight * 1.25;
pictureBox1.Width = (int)previousWidth;
pictureBox1.Height = (int)previousHeight;
// the previous height is to avoid losing the 0.xxxx and so rescaling will
// not eventually end up in a 1 by 1 pixel image or too large.

array.zoomOut(); //makes the lines zoom properly with the picture
icon.zoomOut(); // makes the icons zoom properly with the picture

pictureBox1.Refresh();


// @ opening the file // 
file = System.Drawing.Image.FromFile(openFileDialog1.FileName);

pictureBox1.Image = file;
pictureBox1.Size = new System.Drawing.Size(file.Width, file.Height);
bitmap = new Bitmap(pictureBox1.Image);

pictureBox1.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));

pictureLoaded = true;
previousWidth = pictureBox1.Width;
previousHeight = pictureBox1.Height;

1 个答案:

答案 0 :(得分:0)

你在做WinForms吗?当你说“滞后”时,你的意思是闪烁。

尝试将Form的Property DoubleBuffered设置为True。就像提到here