画一条跟随鼠标的线

发布于 2024-12-03 09:22:55 字数 926 浏览 0 评论 0原文

我想加载一张图片(PNG、JPG、位图),然后我想在图片上画一条线。

目前我使用 PictureBox 来加载我的图片:

这是我的代码的 MouseMove 部分:

If mClickOne = True Then
    If Not mSetDrawPictureAlready Then
        g = Graphics.FromImage(picFormular.Image)
        mRawPicture = picFormular.Image
            mSetDrawPictureAlready = True
    End If
    If mChoosenDrawFunction = DrawFunction.Ausrichten Then
        g.Clear(Color.Transparent)
        g.DrawImage(mRawPicture, picFormular.Location)
        g.DrawLine(Pens.Red, New Point(mClickOnePosX, mClickOnePosY), New Point(e.X, e.Y))
        picFormular.Refresh()
    ElseIf mChoosenDrawFunction = DrawFunction.FeldMakieren Then
        'Missing Code
    Else
        'Nothing
    End If
End If

在此我可以通过单击 PointOne 和单击 PointTwo 来绘制一条线,但是如果调用 MouseMove 事件,我的图片就会消失,所以我在干净的表面上画线。

在我第一次尝试解决这个问题时,我遇到了另一个问题。如果我划定界限,我的旧界限并没有消失。所以,我的整个表面充满了数千条线条。

你们中有人知道如何解决我的问题吗?

I want to load a picture (PNG, JPG, Bitmap) and then, I want to draw a line onto my picture.

At the moment I use a PictureBox to load my picture:

Here is the MouseMove part of my Code:

If mClickOne = True Then
    If Not mSetDrawPictureAlready Then
        g = Graphics.FromImage(picFormular.Image)
        mRawPicture = picFormular.Image
            mSetDrawPictureAlready = True
    End If
    If mChoosenDrawFunction = DrawFunction.Ausrichten Then
        g.Clear(Color.Transparent)
        g.DrawImage(mRawPicture, picFormular.Location)
        g.DrawLine(Pens.Red, New Point(mClickOnePosX, mClickOnePosY), New Point(e.X, e.Y))
        picFormular.Refresh()
    ElseIf mChoosenDrawFunction = DrawFunction.FeldMakieren Then
        'Missing Code
    Else
        'Nothing
    End If
End If

On this I can draw a line with a click on PointOne and a click on PointTwo, but my picture is disappearing if the MouseMove event is called, so I draw my line on a clean surface.

On my first try to fix the problem I got another problem. If I draw my line, my old line didn't disappear. So, my complete surface was full with thousands of lines.

Anyone of you know how to fix my problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文