有人可以给我使用或此库写在VB.NET C#MJPEGStream函数示例
回答
在这里示出的PictureBox流的图像的完整的例子是一个非常,非常简单的形式,它使用AForge.Video.MJPEGStream类。
private MJPEGStream VideoStream = new MJPEGStream();
private void frmMain_Load(object sender, System.EventArgs e)
{
VideoStream.Source = "URL_HERE";
VideoStream.Login = "USERNAME_HERE";
VideoStream.Password = "PASSWORD_HERE";
VideoStream.Start();
}
private void frmMain_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
{
VideoStream.Stop();
}
private void VideoStream_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
Bitmap FrameData = new Bitmap(eventArgs.Frame);
pbStream.Image = FrameData;
}
private void VideoStream_VideoSourceError(object sender, AForge.Video.VideoSourceErrorEventArgs eventArgs)
{
Debug.WriteLine(eventArgs.Description);
}
public frmMain()
{
InitializeComponent();
this.FormClosing += new EventHandler(frmMain_FormClosing);
this.Load += new EventHandler(frmMain_Load);
VideoStream.NewFrame += new EventHandler(VideoStream_NewFrame);
VideoStream.VideoSourceError+= new EventHandler(VideoStream_VideoSourceError);
}
谢谢您的回答,但我不知道为什么我的picturebox没有刷新图像,看这个http://goo.gl/UuqnV –
看你是否添加一个pbStream.Refresh()后,你设置pictureBox im年龄修复它。 – QuantumPhysGuy
另外它看起来不像我的例子,我向你展示了如何订阅该事件。我已经更新了这个例子。看看frmMain(),你应该注意到新的事件订阅。 – QuantumPhysGuy
又如:
Imports AForge.Video
Public Class Form1
Inherits Form
Private stopWatch As Stopwatch = Nothing
Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs)
CloseCurrentVideoSource()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
' create video source
Dim mjpegSource As New MJPEGStream("http://190.6.206.170/video/mjpg.cgi")
mjpegSource.Login = "admin"
mjpegSource.Password = ""
' open it
OpenVideoSource(mjpegSource)
End Sub
' Open video source
Private Sub OpenVideoSource(source As IVideoSource)
' set busy cursor
Me.Cursor = Cursors.WaitCursor
' stop current video source
CloseCurrentVideoSource()
' start new video source
videoSourcePlayer.VideoSource = source
videoSourcePlayer.Start()
' reset stop watch
stopWatch = Nothing
' start timer
timer.Start()
Me.Cursor = Cursors.[Default]
End Sub
' Close video source if it is running
Private Sub CloseCurrentVideoSource()
If videoSourcePlayer.VideoSource IsNot Nothing Then
videoSourcePlayer.SignalToStop()
' wait ~ 3 seconds
For i As Integer = 0 To 29
If Not videoSourcePlayer.IsRunning Then
Exit For
End If
System.Threading.Thread.Sleep(100)
Next
If videoSourcePlayer.IsRunning Then
videoSourcePlayer.[Stop]()
End If
videoSourcePlayer.VideoSource = Nothing
End If
End Sub
' New frame received by the player
Private Sub videoSourcePlayer_NewFrame(sender As Object, ByRef image As Bitmap)
Dim now As DateTime = DateTime.Now
Dim g As Graphics = Graphics.FromImage(image)
' paint current time
Dim brush As New SolidBrush(Color.Red)
g.DrawString(now.ToString(), Me.Font, brush, New PointF(5, 5))
brush.Dispose()
g.Dispose()
End Sub
Private Sub timer_Tick(sender As System.Object, e As System.EventArgs) Handles timer.Tick
Dim videoSource As IVideoSource = videoSourcePlayer.VideoSource
If videoSource IsNot Nothing Then
' get number of frames since the last timer tick
Dim framesReceived As Integer = videoSource.FramesReceived
If stopWatch Is Nothing Then
stopWatch = New Stopwatch()
stopWatch.Start()
Else
stopWatch.[Stop]()
Dim fps As Single = 1000.0F * framesReceived/stopWatch.ElapsedMilliseconds
Me.Text = fps.ToString("F2") & " fps"
stopWatch.Reset()
stopWatch.Start()
End If
End If
End Sub
End Class
所需的控制:
System.Windows.Forms.Timer 'For display fps
Aforge.Controls.VideoSourcePlayer 'For Display the video Img
- 1. MJPEGStream显示流Aforge.Video.dll
- 2. chrome.extension.getBackgroundPage()函数示例
- 3. PHP函数/快速函数示例
- 4. 示例XML位置函数?
- 5. discord.py edit_server函数示例
- 6. C++析构函数示例
- 7. Reentrant和ThreadSafe函数示例
- 8. Portaudio回调函数示例
- 9. 函数式编程示例
- 10. 替换函数示例
- 11. 如何通过示例从Rust生成转置函数示例?
- 12. VB.Net中的递归函数示例
- 13. 解释复制构造函数示例
- 14. 从jQuery调用CakePHP函数的示例
- 15. 如何使用示例函数
- 16. Unity3D中的C#匿名函数示例
- 17. jQuery Masonry删除函数示例
- 18. C++虚函数简单示例
- 19. 如何使用示例函数?
- 20. Modelica示例函数的问题
- 21. 通过函数生成RSpec示例
- 22. C++析构函数(附代码示例)
- 23. 什么是Go示例函数?
- 24. 示例pl/sql函数 - 阐述?
- 25. Android中需要的OpenGL函数示例
- 26. PHP函数声明:函数示例(&$ Test){}解释&?
- 27. 识别在此d3堆叠条形图示例中使用的函数示例
- 28. 函数重载示例在C++中显示错误
- 29. CI实例函数
- 30. mysql案例函数
我想从一个IPCAM的图像,该凸轮已登录验证 –