85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
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;
|
|
|
|
|
|
// include the libraries
|
|
using AForge.Video;
|
|
using AForge.Video.DirectShow;
|
|
using ZXing;
|
|
|
|
namespace HCI_Coursework_EVCHARGE
|
|
{
|
|
public partial class QRReader : Form
|
|
{
|
|
// foxlearn.com/windows-forms/qr-code-scanner-using-camera-in-csharp-380.html
|
|
|
|
|
|
FilterInfoCollection filterInfoCollection;
|
|
VideoCaptureDevice videoCaptureDevice;
|
|
|
|
public QRReader()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
// this will list the available cameras
|
|
filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
|
|
foreach (FilterInfo Device in filterInfoCollection)
|
|
cboCamera.Items.Add(Device.Name);
|
|
cboCamera.SelectedIndex = 0;
|
|
|
|
// start the camera device
|
|
videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[cboCamera.SelectedIndex].MonikerString);
|
|
videoCaptureDevice.NewFrame += FinalFrame_NewFrame;
|
|
videoCaptureDevice.Start();
|
|
timer1.Start();
|
|
}
|
|
|
|
private void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
|
|
{
|
|
// show the video in the picturebox
|
|
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
|
|
}
|
|
|
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
// close the camera device when the app is closed
|
|
if (videoCaptureDevice.IsRunning == true)
|
|
videoCaptureDevice.Stop();
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
// try and detect a barcode/qrcode in the image frame
|
|
BarcodeReader Reader = new BarcodeReader();
|
|
Result result = Reader.Decode((Bitmap)pictureBox1.Image);
|
|
if (result != null && result.Text == "AB87654321")
|
|
{
|
|
BaySelection baySelection = new BaySelection(result.Text);
|
|
baySelection.Show();
|
|
baySelection.FormClosed += delegate
|
|
{
|
|
baySelection = null;
|
|
};
|
|
Close();
|
|
}
|
|
}
|
|
|
|
private void cancel_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
}
|
|
|
|
|