我正在使用Aaron Ballman的Windows功能套件从我的网络摄像头捕获视频。它工作正常,但... ... webcam.startpreview启动出现的摄像头图像和webcam.stoppreview说,并停止视频。
我的问题是,在stoppreview之后,我在canvas控件中留下了一个静止图像,我需要知道如何将该图像保存到磁盘 - 最好是作为jpg文件。
答案 0 :(得分:1)
在这种情况下,画布控件实际上不包含图像;它仅用于指定直接显示在Canvas顶部的系统管理窗口的尺寸和父级。
要获取当前帧,您需要捕获此系统管理窗口的内容。
e.g。将此函数添加到WebCamWFS模块:
Function CaptureFrame(SourceCanvas As Canvas) As Picture
Declare Function GetDC Lib "User32" (HWND As Integer) As Integer
Declare Function BitBlt Lib "GDI32" (DCdest As Integer, xDest As Integer, yDest As Integer, nWidth As Integer, _
nHeight As Integer, DCdource As Integer, xSource As Integer, ySource As Integer, rasterOp As Integer) As Boolean
Declare Function ReleaseDC Lib "User32" (HWND As Integer, DC As Integer) As Integer
Const SRCCOPY = &h00CC0020
Const CAPTUREBLT = &h40000000
Dim hDC, w, h As Integer
hDC = GetDC(mWnd)
w = SourceCanvas.Width
h = SourceCanvas.Height
x = SourceCanvas.Left + SourceCanvas.Window.Left
y = SourceCanvas.Top + SourceCanvas.Window.Top
Dim capture As New Picture(w, h, 24)
Call BitBlt(Capture.Graphics.Handle(1), 0, 0, w, h, hDC, 0, 0, SRCCOPY Or CAPTUREBLT)
Call ReleaseDC(mWnd, hDC)
Return capture
End Function
使用Canvas控件的DrawInto方法将图像复制到 Picture
对象,然后将图片保存到文件中:
Dim mypic As New Picture(TargetCanvas.Width, TargetCanvas.Height, 32)
TargetCanvas.Drawinto(mypic.Graphics, 0, 0)
Dim saveto As FolderItem = GetSaveFolderItem("", "mypic.jpg")
mypic.Save(saveto, Picture.SaveAsJPEG)