C # use Aforge to call a laptop camera to take pictures

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.