tijian_tieying/winform/photo/Form1.cs

91 lines
2.4 KiB
C#
Raw Normal View History

2025-02-20 12:01:17 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using AForge;
using AForge.Controls;
using AForge.Video.DirectShow;
namespace photo
{
public partial class Form1 : Form
{
private FilterInfoCollection _videoDevices;//摄像设备
private VideoCaptureDevice _videoCapture; //捕获设备源
//private Bitmap bitmap;//处理图片
public Form1()
{
InitializeComponent();
try
{
_videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (_videoDevices.Count == 0)
{
throw new ApplicationException();
}
foreach (FilterInfo filter in _videoDevices)
{
comboBox1.Items.Add(filter.Name);
}
}
catch (Exception)
{
comboBox1.Items.Add("没有本地设备");
_videoDevices = null;
}
}
public void ShutCamera()
{
if (videoSourcePlayer1.VideoSource != null)
{
videoSourcePlayer1.SignalToStop();
videoSourcePlayer1.WaitForStop();
videoSourcePlayer1.VideoSource=null;
}
}
public void CameraConn()
{
_videoCapture = new VideoCaptureDevice(_videoDevices[comboBox1.SelectedIndex].MonikerString);
videoSourcePlayer1.VideoSource = _videoCapture;
videoSourcePlayer1.Start();
}
//private void button1_Click(object sender, EventArgs e)
//{
// try
// {
// TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
// string jpgFile = GetImagePath() + "//" + string.Format("{0}.jpg", (Convert.ToInt64(timeSpan.TotalMilliseconds).ToString()));
// bitmap.Save(jpgFile);
// MessageBox.Show("保存成功");
// button1.Enabled = false;
// }
// catch (Exception ee)
// {
// throw ee;
// }
//}
private void button2_Click(object sender, EventArgs e)
{
}
}
}