1.使用:AForge的使用方法
加载aforge.net 安装完成后在工具处可参看:
AForge 的下 的所有面板 其中视频播放的是 videosourcePlayer放入面板。
需要加载的:
using AForge.Video;
using AForge.Video.DirectShow;
///查找所有摄像头设备
private void loadCameraList()
{
FilterInfoCollection cameraDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);//获取摄像头设备
if (cameraDevices.Count == 0)
{
label1.Text = "未找到摄像头。";
}
else if (cameraDevices.Count == 1)
{
VideoCaptureDevice source = new VideoCaptureDevice(cameraDevices[0].MonikerString);
source.NewFrame += new NewFrameEventHandler(NewFrameWorking);//输入新帧后的处理
this.Player.SignalToStop();//关闭信号
this.Player.WaitForStop();
this.Player.VideoSource = source;//加载资源地址
this.Player.Start();
}
}
Bitmap bmp = this.Player.GetCurrentVideoFrame();//获取当前帧
在关闭form的时候,请加载 this.VideoPlayer.Stop();程序才可完全关闭。
public void NewFrameWorking(object sender, NewFrameEventArgs eventArgs)//取帧事件
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();//获取当前帧
bitmap.Save(path, ImageFormat.Jpeg);//保存文件
}
2其他方法使用: