2

Aaron Ballman の Windows Functionality Suite を使用して、Web カメラからビデオをキャプチャしています。それは正常に動作しますが... webcam.startpreview はカメラ画像の表示を開始し、webcam.stoppreview はビデオを停止します。

私の質問は、stoppreview の後、キャンバス コントロールに静止画像が残っており、その画像をディスク (できれば jpg ファイル) に保存する方法を知る必要があるということです。

4

1 に答える 1

1

The canvas control doesn't actually contain the image in this case; it's only used to specify the dimensions and parent of a system-managed window that gets displayed directly on top of the Canvas.

To grab the current frame you'll need to capture the contents of this system-managed window.

e.g. add this function to the WebCamWFS module:

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

Use the DrawInto method of the Canvas control to copy the image to a Picture object, then save the Picture to a file:

  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)

于 2013-12-24T20:03:15.880 に答える