基本信息
源码名称:C#控制摄像头(usb摄像头)拍照新版
源码大小:0.42M
文件格式:.zip
开发语言:C#
更新时间:2019-07-30
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 5 元×
微信扫码支付:5 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AForge.Video.DirectShow;
using System.IO;
using System.Drawing.Imaging;
namespace WinFromDrawing
{
public partial class Form1 : Form
{
private FilterInfoCollection videoDevices;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
// 枚举所有视频输入设备
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
throw new ApplicationException();
foreach (FilterInfo device in videoDevices)
{
cmbCameras.Items.Add(device.Name);
}
cmbCameras.SelectedIndex = 0;
}
catch (ApplicationException)
{
cmbCameras.Items.Add("No local capture devices");
videoDevices = null;
}
}
//启动设备
private void CameraConn()
{
VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[cmbCameras.SelectedIndex].MonikerString);
videPlayer.VideoSource = videoSource;
videPlayer.Start();
}
//启动
private void btStart_Click(object sender, EventArgs e)
{
CameraConn();
}
//拍照
private void btImage_Click(object sender, EventArgs e)
{
try
{
string filePath = @"F:\Temp\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
Bitmap bitmap = videPlayer.GetCurrentVideoFrame();
string fileName = "54250.jpg";
bitmap.Save(filePath fileName, ImageFormat.Jpeg);
bitmap.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("捕获图像失败!" ex.Message, "提示");
}
}
//断开
private void btStop_Click(object sender, EventArgs e)
{
videPlayer.SignalToStop();
videPlayer.WaitForStop();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
videPlayer.SignalToStop();
videPlayer.WaitForStop();
}
private void cmbCameras_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}