vs2012 WinForm
Connect the camera device, you need to introduce
Code:
using Aforge; using Aforge.controls; using aforge.imaging; using Aforge.video; using AForge.Video.DirectShow;
You also need to add Aforge.control in the Toolbox, and then find Videosourceplayer this control to add to the interface
Just find the DLL and drag it to the Toolbox. (Toolbox first to build an option)
There will be a lot of controls in camera, find Videosourceplayer, drag to form
And then I finished the basic setup.
Defining Global Variables
Filterinfocollection videodevices;
Videocapturedevice VideoSource;
public int selecteddeviceindex = 0;
Then connect the camera
1 Private voidBtn_getdevice_click (Objectsender, EventArgs e)2 {3Videodevices =Newfilterinfocollection (filtercategory.videoinputdevice);4Selecteddeviceindex =0;5VideoSource =NewVideocapturedevice (Videodevices[selecteddeviceindex]. monikerstring);//connect the camera. 6Videosource.videoresolution =Videosource.videocapabilities[selecteddeviceindex];7Videosourceplayer1.videosource =VideoSource;8 //Set Newframe event handler9 Videosourceplayer1.start (); Ten}
Photo:
1 Private voidButton1_Click (Objectsender, EventArgs e)2 {3 if(VideoSource = =NULL)4 return;5Bitmap Bitmap =videosourceplayer1.getcurrentvideoframe ();6 stringFileName ="54250.jpg";//DateTime.Now.ToString ("yyyy-mm-dd-hh-mm-ss-ff") + ". jpg";7Bitmap. Save (@"E:\temp\"+FileName, imageformat.jpeg);8 bitmap. Dispose ();9}
This completes the camera function
This is a discussion about the Aforge group, you can add in to discuss with each other, I am not a group of owners not administrators!
205584568, hope not to be offended!
C # use Aforge to call a laptop camera to take pictures