我使用图像的缩小版本,并根据鼠标事件对其进行绘制。我通过设置.BackgroundImage
属性来更新面板上的结果。以下是代码。
private void repaint()
{
Bitmap buffer = new Bitmap(panel1.Width, panel1.Height);
Task.Factory.StartNew(() =>
{
using (Graphics g = Graphics.FromImage(buffer))
{
// Loads a large image from file
Bitmap img = new Bitmap(images[currentImage]);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.Clear(SystemColors.Control);
imgWoP = 0.24f * img.Width;
imgHoP = 0.24f * img.Height;
float trans_x = panel1.Width / 2 - imgWoP / 2;
float trans_y = panel1.Height / 2 - imgHoP / 2;
// Draw a scaled version in the center of the panel
g.DrawImage(img, trans_x, trans_y, imgWoP, imgHoP);
// Do some drawing here
g.DrawLine(...)
g.DrawEllipse(...)
}
}
this.Invoke(new Action(() =>
{
panel1.BackgroundImage = buffer;
}));
});
}
现在,我需要放大这个包含图形的图像。我还需要图形的坐标,我在缩放变化时绘制它。我可以简单地缩放最终位图,然后将其设置为BackgroundImage
,但之后我没有得到任何滚动条,以便我能够看到整个图像。我已将AutoScroll
设置为true。