我正在尝试使用Windows Media Player控件从视频中获取大量帧。它被放置在Panel控件上。
Public Class Form1
Private b As New System.Drawing.Bitmap(160, 120)
Private rct As New Rectangle(0, 0, 160, 120)
Private pb As PictureBox
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
wm.URL = TextBox1.Text
wm.Ctlcontrols.play()
End Sub
Private Sub wm_OpenStateChange(sender As Object, e As AxWMPLib._WMPOCXEvents_OpenStateChangeEvent) Handles wm.OpenStateChange
If e.newState = 13 And wm.playState = 3 Then
Dim g As Graphics = Graphics.FromImage(b)
g.CopyFromScreen(PointToScreen(Panel1.Location), New Drawing.Point(0, 0), b.Size, CopyPixelOperation.SourceCopy)
pb = New PictureBox With {.Width = 160, .Height = 120, .Image = b}
FlowLayoutPanel1.Controls.Add(pb)
Try
While True
wm.Ctlcontrols.currentPosition += 20
Application.DoEvents()
If wm.Ctlcontrols.currentPosition > wm.currentMedia.duration - 20 Then
Exit Sub
End If
b = New Bitmap(160, 120)
g = Graphics.FromImage(b)
g.CopyFromScreen(PointToScreen(Panel1.Location), New Drawing.Point(0, 0), b.Size, CopyPixelOperation.SourceCopy)
pb = New PictureBox With {.Width = 160, .Height = 120, .Image = b}
FlowLayoutPanel1.Controls.Add(pb)
End While
Catch ex As Exception
End Try
End If
End Sub
End Class
因此我希望在FlowLayoutPanel Control中获得许多帧。但是有一些“黑匣子”(重复第一帧)。有什么想法?..如何让WMP更新它的位置和布局?我的想象已经结束了。