-
Notifications
You must be signed in to change notification settings - Fork 1
/
WebcamWindow.xaml.cs
144 lines (118 loc) · 4.07 KB
/
WebcamWindow.xaml.cs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.IO;
namespace CheckCasher
{
/// <summary>
/// Design by Pongsakorn Poosankam
/// Interaction logic for Window1.xaml
/// </summary>
public partial class WebcamWindow : Window
{
public string custID;
public string txnID;
public WebcamWindow()
{
InitializeComponent();
}
public WebCam webcam;
private void mainWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
// TODO: Add event handler implementation here.
WindowInteropHelper helper = new WindowInteropHelper(this);
IntPtr hwnd = GetSystemMenu(helper.Handle, false);
DeleteMenu(hwnd, SC_CLOSE, 0);
//webcam.Start();
}
private void bntStart_Click(object sender, RoutedEventArgs e)
{
webcam.Start();
}
private void bntStop_Click(object sender, RoutedEventArgs e)
{
webcam.Stop();
}
private void bntContinue_Click(object sender, RoutedEventArgs e)
{
webcam.Continue();
}
private void bntCapture_Click(object sender, RoutedEventArgs e)
{
imgCapture.Source = imgVideo.Source;
}
public bool isCheck = false;
private void bntSaveImage_Click(object sender, RoutedEventArgs e)
{
//Helper.SaveImageCapture((BitmapSource)imgCapture.Source);
JpegBitmapEncoder encoder = Helper.GetImage((BitmapSource)imgCapture.Source);
MemoryStream bas = new MemoryStream();
encoder.Save(bas);
if (!isCheck)
{
string qry = "update customers set picture=@picture where id='" + custID + "'";
DB.getInstance().UpdateImage(qry, bas.GetBuffer(), "@picture");
}
else
{
string qry = "update txn set custimg=@custimg where txid='" + txnID + "'";
DB.getInstance().UpdateImage(qry, bas.GetBuffer(), "@custimg");
}
DB.getInstance().close();
bas.Close();
this.Hide();
}
private void bntResolution_Click(object sender, RoutedEventArgs e)
{
webcam.ResolutionSetting();
}
private void bntSetting_Click(object sender, RoutedEventArgs e)
{
webcam.AdvanceSetting();
}
private const uint SC_CLOSE = 0xF060;
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hwnd, bool revert);
[DllImport("user32.dll")]
private static extern bool DeleteMenu(IntPtr hMenu, uint position, uint flags);
private void mainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
webcam.Stop();
}
private void button1_Click_1(object sender, RoutedEventArgs e)
{
this.Hide();
}
private void mainWindow_Deactivated(object sender, EventArgs e)
{
}
private void mainWindow_Activated(object sender, EventArgs e)
{
}
private void mainWindow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (webcam == null)
{
webcam = new WebCam();
webcam.InitializeWebCam(ref imgVideo);
}
if (IsVisible)
{
webcam.Start();
}
else webcam.Stop();
}
}
}