当我将图像加载到Mainform时,我的代码会在图像中绘制一些红色矩形。我已经设置了v& h Scroll-Bars和一个TrackBar来缩放和滚动。单独使用时它们工作得很好。
这是我缩放和滚动时的样子:
但是当我使用两者时,我会在图像中移动这些红色矩形。
缩放和滚动后移动的矩形:
我正在调用Draw(Graphics g),它位于MainForm_Paint的另一个类中,如下所示:
private void MainForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Call the Draw function of the ImageProcessing class
e.Graphics.TranslateTransform(-hScrollBar.Value, -vScrollBar.Value);
e.Graphics.ScaleTransform(ImageZoomTrackbar.Value / 100f, ImageZoomTrackbar.Value / 100f);
imageprocessing.Draw(e.Graphics);
}
其他课程:
private EImageBW8 sourceImage = new EImageBW8();
private EOCR ocrTool = new EOCR();
public void Initialize()
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
/// Load the image featuring the characters
sourceImage.Load(dlg.FileName);
}
/// Set the characters color
ocrTool.TextColor = EOCRColor.WhiteOnBlack;
// Build blobs
ocrTool.BuildObjects(sourceImage);
// Build chars
ocrTool.FindAllChars(sourceImage);
}
catch (EException exc)
{
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void Draw(Graphics g)
{
try
{
/// Exit if no image has been loaded
if (sourceImage.IsVoid) return;
/// Draw the source image
sourceImage.Draw(g, g.Transform.Elements[0], g.Transform.Elements[3], g.Transform.OffsetX, g.Transform.OffsetY);
/// Draw the character Patterns
ocrTool.DrawChars(g, g.Transform.Elements[0], g.Transform.Elements[3], g.Transform.OffsetX, g.Transform.OffsetY);
}
catch (EException exc)
{
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
知道为什么会这样吗?