01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.ComponentModel;
04.
using
System.Data;
05.
using
System.Drawing;
06.
using
System.Linq;
07.
using
System.Text;
08.
using
System.Windows.Forms;
09.
using
AForge.Video.DirectShow;
10.
using
BarcodeLib.BarcodeReader;
11.
12.
namespace
LeerQR
13.
{
14.
public
partial
class
Form1 : Form
15.
{
16.
public
Form1()
17.
{
18.
InitializeComponent();
19.
}
20.
21.
22.
23.
24.
25.
26.
27.
28.
private
FilterInfoCollection Dispositivos;
29.
30.
private
VideoCaptureDevice FuenteDeVideo;
31.
private
void
Form1_Load(
object
sender, EventArgs e)
32.
{
33.
34.
Dispositivos =
new
FilterInfoCollection(FilterCategory.VideoInputDevice);
35.
36.
foreach
(FilterInfo x
in
Dispositivos)
37.
{
38.
comboBox1.Items.Add(x.Name);
39.
}
40.
comboBox1.SelectedIndex = 0;
41.
}
42.
private
void
button1_Click(
object
sender, EventArgs e)
43.
{
44.
45.
timer1.Enabled =
true
;
46.
47.
48.
FuenteDeVideo =
new
VideoCaptureDevice(Dispositivos[comboBox1.SelectedIndex].MonikerString);
49.
50.
videoSourcePlayer1.VideoSource = FuenteDeVideo;
51.
52.
videoSourcePlayer1.Start();
53.
}
54.
55.
private
void
button2_Click(
object
sender, EventArgs e)
56.
{
57.
58.
timer1.Enabled =
false
;
59.
60.
61.
62.
videoSourcePlayer1.SignalToStop();
63.
}
64.
65.
private
void
timer1_Tick(
object
sender, EventArgs e)
66.
{
67.
68.
if
(videoSourcePlayer1.GetCurrentVideoFrame() !=
null
)
69.
{
70.
71.
Bitmap img =
new
Bitmap(videoSourcePlayer1.GetCurrentVideoFrame());
72.
73.
string
[] resultados = BarcodeReader.read(img, BarcodeReader.QRCODE);
74.
75.
img.Dispose();
76.
77.
if
(resultados !=
null
&& resultados.Count() > 0)
78.
{
79.
80.
if
(resultados[0].IndexOf(
"1111"
) != -1)
81.
{
82.
83.
resultados[0] = resultados[0].Replace(
"1111"
,
""
);
84.
listBox1.Items.Add(resultados[0]);
85.
}
86.
}
87.
}
88.
}
89.
}
90.
}