首先看看调用摄像头
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);//摄像头实例对象
int sumVideo = videoDevices.Count;//找到计算机所有的摄像头 数量 ,没有摄像头的话 就等于 0
videoSource.ProvideSnapshots = true; //是否设定快门键 作用于摄像头,下面 videoSource_SnapshotFrame; 快门事件是否生效.
videoSource.SnapshotFrame += videoSource_SnapshotFrame;快门事件
videoSource.NewFrame += videoSource_NewFrame; //在此事件中把把摄像头共享给其他控件使用 如(pic图片控件,摄像头画面可有在显示在pic控件中)
如果使用 Controls videoSourcePlayer控件的话.则使用以下语句 获取摄像源
videoSourcePlayer = new AForge.Controls.VideoSourcePlayer();
videoSourcePlayer.VideoSource = videoSource;
videoSourcePlayer.Start();
videoSource_NewFrame 事件实现
void videoSource_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
Image img = (Image)eventArgs.Frame.Clone();
PicVideo.BackgroundImage = img;
GC.Collect();
}
这样就可以把摄像头画面 赋予 PicVideo 控件中显示(PictureBox图片控件)
videoSource_SnapshotFrame 事件实现 - 快门事件(如摄像头有快门键话,按下就可以触发此事件)-如出现按下快门键没有触发此事件的情况,则可能摄像头按键不支持.(情况较少出现)
void videoSource_SnapshotFrame(object sender, NewFrameEventArgs eventArgs)
{
try
{
//按下快门事件,就截图照片. 赋值于 pictureBox1 控件中显示
pictureBox1.BackgroundImage = Image.FromHbitmap(videoSourcePlayer.GetCurrentVideoFrame().GetHbitmap());
}
catch(Exception ex)
{
}
}
按以上步骤 正常情况是可成功操作摄像头的.
demo 下载地址:百度云 http://pan.baidu.com/s/1o6A1D9o (附带DLL)