FrmTest.cs
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using AForge.Video;
using AForge.Video.DirectShow;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CodeTest
{
public partial class FrmTest : Form
{
public FrmTest()
{
InitializeComponent();
}
private FilterInfoCollection videoDevices;
private void FrmTest_Load(object sender, EventArgs e)
{
//var zipHelper = new CompressHelper();
//zipHelper.CompressSingle(@"D:\Data Matrix ECC 200.dcm");
//List<string> strList = new List<string>() { @"D:\Data Matrix ECC 200.dcm", @"D:\ilmergeTest.txt", @"D:\QR Code.dcm" };
//zipHelper.CompressMulti(strList.ToArray(), @"D:\test.gz");
//zipHelper.DeCompressMulti(@"D:\test.gz", @"D:\web\");
comboBox1.Items.Clear();
this.videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo v in videoDevices)
{
comboBox1.Items.Add(v.Name);
}
if (comboBox1.Items.Count > 0)
{
comboBox1.SelectedIndex = 0;
}
}
private void button1_Click(object sender, EventArgs e)
{
int index = comboBox1.SelectedIndex;
if (this.videoDevices.Count > index)
{
VideoCaptureDevice source = new VideoCaptureDevice(this.videoDevices[index].MonikerString);
this.videoSourcePlayer.SignalToStop();
this.videoSourcePlayer.WaitForStop();
this.videoSourcePlayer.VideoSource = source;
this.videoSourcePlayer.Start();
}
comboBox1.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
videoSourcePlayer.Stop();
comboBox1.Enabled = true;
}
private int flag = 0;
private void btnGetImage_Click(object sender, EventArgs e)
{
if (videoSourcePlayer.IsRunning)
{
flag = 0;
videoSourcePlayer.NewFrame += video_NewFrame;
//string path = Application.StartupPath + @"\ImagePath\Image.bmp";
Bitmap bit = (Bitmap)(videoSourcePlayer.GetCurrentVideoFrame()).Clone() ;
//bit.Save(path, ImageFormat.Bmp);
//MessageBox.Show("成功保存图片至:" + path);
}
}
private void video_NewFrame(object sender, ref Bitmap image)
{
Bitmap bitmap = (Bitmap)image.Clone();
if (flag == 0)
{
string dir = Application.StartupPath + @"/ImagePath/ ";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
string img = dir + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
bitmap.Save(img);
flag = 1;
}
}
}
}