This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CapturePicture.vb
190 lines (115 loc) · 5.5 KB
/
CapturePicture.vb
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
Imports AForge.Video
Imports AForge.Video.DirectShow
Public Class CapturePicture
Dim gbCamera As VideoCaptureDevice
Dim bmp As Bitmap
Private Sub RoundButtonStartCamera(btn As Button)
btn.FlatStyle = FlatStyle.Flat
btn.FlatAppearance.BorderSize = 0
btn.Cursor = Cursors.Hand
Dim Raduis As New Drawing2D.GraphicsPath
Raduis.StartFigure()
Raduis.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
Raduis.AddLine(10, 0, btn.Width - 20, 0)
Raduis.AddArc(New Rectangle(btn.Width - 20, 0, 20, 20), -90, 90)
Raduis.AddLine(btnStartCamera.Width, 20, btn.Width, btn.Height - 10)
Raduis.AddArc(New Rectangle(btn.Width - 25, btn.Height - 25, 25, 25), 0, 90)
Raduis.AddLine(btn.Width - 10, btn.Width, 20, btn.Height)
Raduis.AddArc(New Rectangle(0, btn.Height - 20, 20, 20), 90, 90)
Raduis.CloseFigure()
btnStartCamera.Region = New Region(Raduis)
End Sub
Private Sub RoundButtonCapture(btn As Button)
btn.FlatStyle = FlatStyle.Flat
btn.FlatAppearance.BorderSize = 0
btn.Cursor = Cursors.Hand
Dim Raduis As New Drawing2D.GraphicsPath
Raduis.StartFigure()
Raduis.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
Raduis.AddLine(10, 0, btn.Width - 20, 0)
Raduis.AddArc(New Rectangle(btn.Width - 20, 0, 20, 20), -90, 90)
Raduis.AddLine(btnCapture.Width, 20, btn.Width, btn.Height - 10)
Raduis.AddArc(New Rectangle(btn.Width - 25, btn.Height - 25, 25, 25), 0, 90)
Raduis.AddLine(btn.Width - 10, btn.Width, 20, btn.Height)
Raduis.AddArc(New Rectangle(0, btn.Height - 20, 20, 20), 90, 90)
Raduis.CloseFigure()
btnCapture.Region = New Region(Raduis)
End Sub
Private Sub RoundButtonSavePicture(btn As Button)
btn.FlatStyle = FlatStyle.Flat
btn.FlatAppearance.BorderSize = 0
btn.Cursor = Cursors.Hand
Dim Raduis As New Drawing2D.GraphicsPath
Raduis.StartFigure()
Raduis.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
Raduis.AddLine(10, 0, btn.Width - 20, 0)
Raduis.AddArc(New Rectangle(btn.Width - 20, 0, 20, 20), -90, 90)
Raduis.AddLine(btnSavePicture.Width, 20, btn.Width, btn.Height - 10)
Raduis.AddArc(New Rectangle(btn.Width - 25, btn.Height - 25, 25, 25), 0, 90)
Raduis.AddLine(btn.Width - 10, btn.Width, 20, btn.Height)
Raduis.AddArc(New Rectangle(0, btn.Height - 20, 20, 20), 90, 90)
Raduis.CloseFigure()
btnSavePicture.Region = New Region(Raduis)
End Sub
Private Sub Captures(sender As Object, eventArgs As NewFrameEventArgs)
bmp = DirectCast(eventArgs.Frame.Clone(), Bitmap)
PictureBox1.Image = DirectCast(eventArgs.Frame.Clone(), Bitmap)
End Sub
Private Sub CapturePicture_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
If TeacherData.cmbCapture.Text = "TeacherInfo" Then
TeacherData.cmbCapture.Text = ""
ElseIf StudentEnrollment.cmbEnrollment.Text = "Enrollment" Then
StudentEnrollment.cmbEnrollment.Text = ""
ElseIf EnrollmentData.cmbCapture.Text = "EnrollmentData" Then
EnrollmentData.cmbCapture.Text = ""
ElseIf ChangeInfo.cmbCapture.Text = "ChangeInfo" Then
ChangeInfo.cmbCapture.Text = ""
End If
If gbCamera Is Nothing Then
'do nothing
Else
gbCamera.Stop()
End If
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical, "Camera error")
Exit Sub
End Try
End Sub
Private Sub BtnStartCamera_Click(sender As Object, e As EventArgs) Handles btnStartCamera.Click
Try
Dim camera As New VideoCaptureDeviceForm
If camera.ShowDialog() = Windows.Forms.DialogResult.OK Then
gbCamera = camera.VideoDevice
AddHandler gbCamera.NewFrame, New NewFrameEventHandler(AddressOf Captures)
gbCamera.Start()
End If
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical, "Camera error")
Exit Sub
End Try
End Sub
Private Sub BtnCapture_Click(sender As Object, e As EventArgs) Handles btnCapture.Click
PictureBox2.Image = PictureBox1.Image
If TeacherData.cmbCapture.Text = "TeacherData" Then
TeacherData.PictureID.Image = PictureBox1.Image
ElseIf EnrollmentData.cmbCapture.Text = "EnrollmentData" Then
EnrollmentData.PictureID.Image = PictureBox1.Image
ElseIf StudentEnrollment.cmbEnrollment.Text = "Enrollment" Then
StudentEnrollment.StudentPic.Image = PictureBox1.Image
ElseIf ChangeInfo.cmbCapture.Text = "ChangeInfo" Then
ChangeInfo.IDPicture.Image = PictureBox1.Image
End If
End Sub
Private Sub BtnSavePicture_Click(sender As Object, e As EventArgs) Handles btnSavePicture.Click
SaveFileDialog1.DefaultExt = ".jpg"
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox2.Image.Save(SaveFileDialog1.FileName, Imaging.ImageFormat.Jpeg)
End If
End Sub
Private Sub CapturePicture_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RoundButtonStartCamera(btnStartCamera)
RoundButtonCapture(btnCapture)
RoundButtonSavePicture(btnSavePicture)
End Sub
End Class