2009-10-01 截取 Web Cam CCD 影像存成圖 18723 0 VB.Net / C#.Net / 摘要:截取 Web Cam CCD 影像存成圖 截取 Web Cam CCD 影像存成圖Call API capCreateCaptureWindowA 處理Imports System Imports System.Drawing.Imaging Imports System.Windows.Forms Public Class Form1 ' 宣告 API Private Declare Function SendMessageA Lib "user32" _ (ByVal hwnd As Int32, ByVal wMsg As Int32, _ ByVal wParam As Int32, ByVal lParam As Int32) As Int32 Private Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _ (ByVal lpszWindowName As String, ByVal dwStyle As Int32, _ ByVal X As Int32, ByVal Y As Int32, _ ByVal nWidth As Int32, ByVal nHeight As Int32, _ ByVal hwndParent As Int32, ByVal nID As Int32) As Int32 '設定 Timer 1/4 秒抓一張圖 Private WithEvents tmr As New Timer With {.Interval = 250} Private pic As New PictureBox With {.Top = 0, .left = 0, .Width = 0, .Height = 0, .Visible = False} Private hWnd As Int32 = 0 Private Sub Form1_Load(ByVal s As Object, ByVal e As EventArgs) Handles MyBase.Load WindowState = FormWindowState.Minimized ' 表單最小化 crtCapWin() ' 建立並設定影像抓取 tmr.Start() ' 啟動 Timer End Sub Private Sub crtCapWin() '設定截取影像 hWnd = capCreateCaptureWindowA("Capture", 1342177280, 0, 0, 640, 480, pic.Handle.ToInt32, 0) SendMessageA(hWnd, 1034, 0, 0) SendMessageA(hWnd, 1038, 44, 0) SendMessageA(hWnd, 1974, 1, 0) SendMessageA(hWnd, 1976, 66, 0) End Sub ' Timer tick 事件 Private Sub tmr_Tick(ByVal s As Object, ByVal e As EventArgs) Handles tmr.Tick SendMessageA(hWnd, 1084, 0, 0) SendMessageA(hWnd, 1054, 0, 0) '存圖於 C:\... Clipboard.GetImage.Save(String.Format("C:\{0}.{1}", Now.ToString("yyyyMMddhhmmss"), "jpg"), ImageFormat.Jpeg) End Sub '結束 Private Sub Form1_FormClosed(ByVal s As Object, ByVal e As FormClosedEventArgs) Handles Me.FormClosed tmr.Stop() SendMessageA(hWnd, 1035, 0, 0) End Sub End Class capCreateCaptureWindowACaptureCCDWebCam 回首頁