我正在研究应该使用计时器来动画桌面背景的代码,并且我使用下面的代码实现了该操作,但是我不打算将它随机更改为随机壁纸,所以这里是我的问题,我使用(ffmpeg)命令行从一个GIF
图像中提取所有帧,然后我运行一个具有较低间隔(100)的计时器,以遍历所有帧并更改使用User32.dll
API的背景,但问题是动画不是很流畅,就像在浏览器中打开它一样,并且在动画过程中该程序会非常缓慢,所以我不知道是否有其他方式可以更改背景没有滞后,这是我迄今为止所做的:在VB中使用计时器动画Windows桌面背景
Imports System.IO
Public Class Form1
Private Declare Auto Function SystemParametersInfo Lib "user32.dll" (ByVal X As Integer, ByVal Y As Integer, ByVal Z As String, ByVal W As Integer) As Integer
Dim FrameX As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'If the frame is not exist then loop from the begenning with the frame 0.
If Not File.Exists(Application.StartupPath & "\Frames\animation" & FrameX & ".png") Then
FrameX = 0
End If
Try
SystemParametersInfo(20, 0, Application.StartupPath & "\Frames\animation" & FrameX & ".png", 1 Or 2)
Catch ex As Exception : End Try
FrameX += 1
Timer1.Start()
End Sub
End Class
你是什么意思** **光滑,你的意思是不是快? 另外,我不明白你为什么把Timer1.Stop()放在Timer1_Tick和Timer1.Start()的开头。 尝试删除Timer1.Stop()。您也可以尝试降低间隔。 – Youssef13
@ Youssef13,是的,它非常“缓慢”,不仅速度慢,它可能会冻结一秒钟,然后跳过2-3帧。 –
我建议你不要让** Catch **部分变空。也许有一个例外发生,使一些帧被跳过。 – Youssef13