我正在使用网络摄像头开发一个安全摄像头应用程序,该摄像头每隔 x 用户选择的毫秒数拍摄一张照片。(默认为 2000 毫秒,或 2 秒)目前文件默认存储在用户的硬盘上。
我想要做的不是将其保存为 1.bmp、2.bmp、3.bmp 等:而是保存到日期和时间,例如。"Jul 03 12:14:53.bmp" 使用这个 - DateTime.Now.ToString("MMM dd hh:mm:ss")
但是显然我没有运气,并继续出错。所以这是我得到所有这些错误之前的代码,任何帮助将不胜感激。谢谢!
Dim frame As Integer
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
frame += 1
Dim r As RECT = New RECT()
GetWindowRect(hWnd, r)
Dim cWidth As Integer = r.right - r.left
Dim cHeight As Integer = r.bottom - r.top
Dim bmp As Bitmap = New Bitmap(cWidth, cHeight)
Dim gfx As Graphics = Graphics.FromImage(bmp)
Dim gHdc As IntPtr = gfx.GetHdc()
'refresh the image
SendMessage(hWnd, WM_CAP_GRAB_FRAME, IntPtr.Zero, IntPtr.Zero)
PrintWindow(hWnd, gHdc, 0)
gfx.ReleaseHdc(gHdc)
gfx.Dispose()
bmp.Save("photos-taken\" & frame & ".bmp")
bmp.Dispose()
End Sub
Private Sub RecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecordToolStripMenuItem.Click
If Not Directory.Exists("photos-taken") Then
Directory.CreateDirectory("photos-taken")
End If
If RecordToolStripMenuItem.Checked = False Then
RecordToolStripMenuItem.Checked = True
frame = 0
Timer2.Interval = 2000
Timer2.Start()
Else
RecordToolStripMenuItem.Checked = False
frame = 0
Timer2.Stop()
End If
End Sub