我正在使用Aaron Ballman的Windows功能套件从网络摄像头捕获视频。它很好用,但是。。。webcam.startpreview开始显示相机图像,webcam.stopreview按照它所说的操作并停止视频。
我的问题是,在stopperview之后,画布控件中留下了一个静态图像,我需要知道如何将该图像保存到磁盘上,最好是保存为jpg文件。
在这种情况下,画布控件实际上并不包含图像;它只用于指定直接显示在画布顶部的系统管理窗口的维度和父窗口。
要获取当前帧,您需要捕获此系统管理窗口的内容。
例如,将此功能添加到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)