嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
可以搜素本机摄像头,并呈现图像,实现拍照功能
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private FilterInfoCollection videodevices;
private VideoCaptureDevice Source;
private int indexf = 0;
private void Form1_Load(object sender, EventArgs e)
{
}
private void Camlist()
{
videodevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videodevices.Count == 0)
{
MessageBox.Show("未找到摄像头设备");
}
foreach (FilterInfo device in videodevices)
{
comboBox1.Items.Add(device.Name);
}
}
private void button1_Click(object sender, EventArgs e)//搜索设备
{
Camlist();
}
private void button2_Click(object sender, EventArgs e)//打开摄像头
{
indexf = comboBox1.SelectedIndex;
if (indexf < 0)
{
MessageBox.Show("请选择一个摄像头");
return;
}
this.pictureBox1.Visible = false;
this.videoSourcePlayer1.Visible = true;
//videoDevices[Indexof]确定出用哪个摄像头了。
Source = new VideoCaptureDevice(videodevices[indexf].MonikerString);
//设置下像素,这句话不写也可以正常运行:
Source.VideoResolution = Source.VideoCapabilities[indexf];
//在videoSourcePlayer1里显示
videoSourcePlayer1.VideoSource = Source;
videoSourcePlayer1.Start();
}
private void button3_Click(object sender, EventArgs e)//抓拍
{
if (Source == null)
{
MessageBox.Show("请先打开摄像头");
return;
}
//videoSourcePlayer继承Control父类,定义 GetCurrentVideoFrame能输出bitmap
Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
pictureBox1.Image = bitmap;
this.videoSourcePlayer1.Visible = false;
this.pictureBox1.Visible = true;
//这里停止摄像头继续工作 当然videoSourcePlayer里也定义了 Stop();用哪个都行
videoSourcePlayer1.Stop();
}
}