位图图像,鼠标移动事件vb.net期间的gr.drawRectangle

时间:2017-11-22 12:26:56

标签: vb.net bitmap

编码时:

Sub PcbOriginalMouseMove(sender As Object, e As MouseEventArgs)
        Try
            If isSelecting = True Then
                x1 = e.X
                y1 = e.Y
                Dim bm As New Bitmap(pcbOriginal.Image)

                Using gr As Graphics = Graphics.FromImage(bm)
                    gr.DrawRectangle(Pens.Red, Math.Min(x0,x1), Math.Min (y0,y1), Math.Abs(x0-x1), Math.Abs(y0-y1))
                End Using

                pcbOriginal.Image = bm
            End If
        Catch ex As Exception 
        End Try 
End Sub

我在图片中看到了一个重复的矩形(鼠标移动时选定的区域):

鼠标快速移动:

drawn rectangle when moving the mouse quickly

鼠标移动缓慢:

drawn rectangle when moving the mouse slowly

1 个答案:

答案 0 :(得分:0)

这是怎么回事:

尝试

        If isSelecting = True Then

            x1 = e.X
            y1 = e.Y

            originalImage =  Image.FromFile("D:\Imagenes\Logos\Logo-Tecnicos-para-Chile.jpg")

            Dim bm As New Bitmap (originalImage)

            Using gr As Graphics = Graphics.FromImage(bm)

                gr.DrawRectangle(Pens.Red, Math.Min(x0,x1), Math.Min (y0,y1), Math.Abs(x0-x1), Math.Abs(y0-y1))

            End Using

            originalImage = bm 
            pcbOriginal.Image = originalImage
        End If

    Catch ex As Exception 
    End Try[enter image description here][1]

结果:用户选择另一个picbox [1]中显示的图片区域:https://i.stack.imgur.com/ihLXg.png