PictureBox图像上的绘制线但是没有穿过整个高度或宽度

时间:2015-04-02 14:20:40

标签: c# picturebox system.drawing

我在画框上垂直和水平画线,但是线条没有全长,它们在高度和宽度上显得较少我在相机的帧事件中绘制图像然后在图像上显示线条但是它们没有出现完全我的代码如下 图片框的尺寸模式为缩放

    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();
    }

1 个答案:

答案 0 :(得分:0)

CopyToBitmap 有一个错误: 它在手册中说它返回内存中图像的副本,但它实际上给出了对图像的引用。 在您的情况下,这意味着当您绘制线条时,缓冲区中正在绘制一个新图像并覆盖图像的一部分。 如果高 FPS 速率对您来说并不重要,请将位图复制到新实例,然后在单独的线程中绘制和渲染它。 我使用 15 FPS 显示效果很好。