0

我正在制作闭路电视摄像机之类的东西,我希望图片框中的图片每十秒钟更换一次,有人可以帮我吗?我试过使用

pic1.Image = Image.FromFile("C:\Documents and Settings\IT\My Documents\Downloads\whitehouse 
System.Threading.Thread.Sleep(10000)
pic1.Image = Image.FromFile("C:\Documents and Settings\IT\My Documents\Downloads\penatagon")
4

1 回答 1

3

有几件事:如果这些图像不是太大而且太多,您应该考虑预先将它们全部预加载:

Dim images As New List(Of Image)()
images.add(Image.FromFile(Somefilepath))
images.add(Image.FromFile(your2ndFilepath))
' etc.

现在创建一个每 10 秒计时一次的计时器:

Dim pictureChangeTimer As New Timer()
'Creates a timer
AddHandler pictureChangeTimer.Tick, AddressOf pictureChangeTimer_tick
'creates an event handler, simply type in pictureChangeTimer.Tick += and hit tab twice. this will automatically create the method for you
' Sets the timer interval to 10 seconds.
pictureChangeTimer.Interval = 10000
pictureChangeTimer.Start()

现在在一个单独的功能中,您可以在每次活动启动时更改您的图片:

Private Sub pictureChangeTimer_tick(sender As Object, e As EventArgs)
    'if using a list
    index = (index + 1) Mod images.Count()
    pic1.Image = images(index)
    'using your original example
    'pic1.Image = Image.FromFile("C:\Documents and Settings\IT\My Documents\Downloads\whitehouse.jpg")
End Sub
于 2013-06-17T20:58:35.737 回答