我在图片框上垂直和水平绘制线条,但线条没有完全混合,它们在高度和宽度上看起来更小。我在相机的帧内事件中绘制图像,然后在图像上显示线条,但它们没有完全混合。我的代码如下图片框的大小模式为缩放
private void onFrameEvent(object sender, EventArgs e)
{
uEye.Camera Camera = sender as uEye.Camera;
Int32 s32MemID;
Bitmap bmp = null;
Camera.Memory.GetActive(out s32MemID);
// bmpbackup = null;
Camera.Memory.CopyToBitmap(s32MemID, out bmp);
try
{
bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
DisplayWindow.Image = bmp;
}
catch (Exception)
{
}
if (Const.cal == true)
{
g1.DrawLine(p, new Point(lastPoint4LeftClick.X, 0), new Point(lastPoint4LeftClick.X, DisplayWindow.Size.Height));
g1.DrawLine(p, new Point(0, lastPoint4RightClick.Y), new Point(DisplayWindow.Size.Width, lastPoint4RightClick.Y));
g1.DrawLine(p, new Point(last2ndPoint4LeftClick.X, 0), new Point(last2ndPoint4LeftClick.X,DisplayWindow.ClientSize.Height));
g1.DrawLine(p, new Point(0, last2ndPoint4RightClick.Y), new Point(DisplayWindow.Size.Width, last2ndPoint4RightClick.Y));
g1.DrawLine(p, new Point(0, 0), new Point(0, 1));
Const.Xcalfactor = Math.Abs(lastPoint4LeftClick.X - last2ndPoint4LeftClick.X);
Const.Ycalfactor = Math.Abs(lastPoint4RightClick.Y - last2ndPoint4RightClick.Y);
}
GC.Collect();
}
CopyToBitmap中存在一个错误:它在手册中说,它在内存中返回图像的副本,但实际上它给出了图像的参考。在您的情况下,这意味着当您绘制线条时,缓冲区中正在绘制一个新图像,并覆盖图像的一部分。如果高FPS速率对您来说并不重要,请将位图复制到新实例,然后在单独的线程中绘制和渲染它。我使用15 FPS的显示效果很好。