基本信息
源码名称:使用AForge.Net打开摄像头抓拍图片
源码大小:0.58M
文件格式:.zip
开发语言:C#
更新时间:2020-03-17
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
使用AForge.Net抓拍图片
using AForge.Video.DirectShow;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace AForgeTestApp
{
public partial class MainForm : Form
{
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource;
private int Indexof = 0;
public MainForm()
{
InitializeComponent();
}
//添加所有的摄像头到combobox列表里
private void Camlist()
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
{
MessageBox.Show("未找到摄像头设备");
}
foreach (FilterInfo device in videoDevices)
{
Cameralist.Items.Add(device.Name);
}
}
private void Form1_Load(object sender, EventArgs e)
{
Camlist();
}
private void OpenVoidVtn_Click(object sender, EventArgs e)
{
Indexof = Cameralist.SelectedIndex;
if (Indexof < 0)
{
MessageBox.Show("请选择一个摄像头");
return;
}
//this.pictureBox1.Visible = false;
this.videoSourcePlayer1.Visible = true;
//videoDevices[Indexof]确定出用哪个摄像头了。
videoSource = new VideoCaptureDevice(videoDevices[Indexof].MonikerString);
//设置下像素,这句话不写也可以正常运行:
videoSource.VideoResolution = videoSource.VideoCapabilities[Indexof];
//在videoSourcePlayer1里显示
videoSourcePlayer1.VideoSource = videoSource;
videoSourcePlayer1.Start();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
//这里停止摄像头继续工作 当然videoSourcePlayer里也定义了 Stop();用哪个都行
videoSourcePlayer1.Stop();
// videoSourcePlayer1.SignalToStop(); videoSourcePlayer1.WaitForStop();
}
private void SnapPictureBtn_Click(object sender, EventArgs e)
{
if (videoSource == null)
{
MessageBox.Show("请先打开摄像头");
return;
}
//videoSourcePlayer继承Control父类,定义 GetCurrentVideoFrame能输出bitmap
Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
bitmap.Save($"{DateTime.Now:yyyyMMddHHmmss}.jpeg");
}
}
}