在图像周围绘制平滑的矩形(带有动画)

时间:2020-11-03 10:37:39

标签: vb.net

我在VB中创建了一个项目,在其中我以全屏方式在PictrueBox上显示图像,并且在图像周围使用背景色“黑色”设置了填充10。 现在,我尝试在填充区域上绘制一个带有“红色”颜色的矩形,该矩形将填充从0,0位置到屏幕宽度位置的线条。 我正在使用Graphics of Paint事件绘制一个Rectangle,并在BG worker中增加Rectangle的宽度。 一切工作正常,感觉好像有一个红色边框正在用动画绘制,但是动画不像平滑,看上去像跳动(在动画过程中)。

我想要VB中的平滑动画而不像跳动,我可以在VB中进行平滑动画吗?

'code of myScreen_paint event
Private Sub myScreen_Paint(sender As Object, e As PaintEventArgs) Handles PicturePlayer.Paint
    ' Create solid brush.
    Dim blueBrush As New SolidBrush(Color.Red)

    ' Create rectangle
    rect = New Rectangle(0, 0, posX, 10)
End Sub

'code of Background Worker that redraw Rectangle (but not animation like smooth but jumpy)
Private Sub BgWorkerProg_DoWork(sender As Object, e As DoWorkEventArgs) Handles BgWorkerProg.DoWork
    System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
    While True
        If BgWorkerProg.CancellationPending Then
            e.Cancel = True
            Return
        End If
        posX = posX + ((Me.Width / (PlayingAsset.Duration / 2)) / 4) ' duration is the time to show the image on screen.
        Me.Invalidate()
        Me.Refresh()

    End While

End Sub

请有人在这里帮助我。 谢谢

0 个答案:

没有答案