我使用 AForge 库制作了这个小程序,它将网络摄像头的实时信息显示到 PictureBox 中。
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideoDevice;
private void Form1_Load(object sender, EventArgs e)
{
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
try
{
foreach (FilterInfo VidCapDev in VideoCaptureDevices)
{
comboBox1.Items.Add(VidCapDev.Name);
comboBox1.SelectedIndex = 0;
}
FinalVideoDevice = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
FinalVideoDevice.NewFrame += new NewFrameEventHandler(FinalVideoDevice_NewFrame);
FinalVideoDevice.Start();
}
catch
{
MessageBox.Show("No camera found. Please connect your camera and click RESET.");
}
}
//////////////////////////////////////////////////////////////////////////////////////////
void FinalVideoDevice_NewFrame(object sender, NewFrameEventArgs e)
{
try
{
pictureBox1.Image = (Bitmap)e.Frame.Clone();
}
catch { }
}
但我还需要从 IP 摄像机获取流。任何想法什么是获得它的最佳方式?