using System;
using System.Collections.Generic;
using System.ComponentModel;
//JK改寫完成 可連續補捉成圖片~


using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace WEBCAM
{

class CCapture
{
const int WM_CAP_DRIVER_CONNECT = 0x40a;
const int WM_CAP_DRIVER_DISCONNECT = 0x40b;
const int WM_CAP_EDIT_COPY = 0x41e;
const int WS_CHILD = 0x40000000;
const int WS_VISIBLE = 0x10000000;
const int WM_CAP_GRAB_FRAME = 0x43c;
[DllImport("avicap32")]
static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
[DllImport("user32")]
static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)] object lParam);
[DllImport("user32")]
static extern bool DestroyWindow(IntPtr hwnd);
// [DllImport("user32")]
// public static extern int FindWindow(string lpClassName, string lpWindowName);



//----------
Bitmap MyBitmap = new Bitmap(600, 600);
IntPtr intDeviceHandle = (IntPtr)0;
byte[] baDeviceName = new byte[1];

public void CaptureA()
{
//----------




//建立設備的Handle


if (intDeviceHandle == (IntPtr)0)
{
intDeviceHandle = capCreateCaptureWindowA(baDeviceName, WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, Form1.ActiveForm.Handle, 0);

SendMessage(intDeviceHandle, WM_CAP_DRIVER_CONNECT, 0, 0); //連接設備
}


if (SendMessage(intDeviceHandle, WM_CAP_GRAB_FRAME, 0, 0) > 0) //如果有截取到畫面
{

if (SendMessage(intDeviceHandle, WM_CAP_EDIT_COPY, 0, 0) > 0) //如果有Copy到剪貼簿
{

IDataObject MyClipboardObject = Clipboard.GetDataObject();//取得剪貼簿物件

if (MyClipboardObject.GetDataPresent(typeof(Bitmap))) //看看是不是點陣圖

MyBitmap = (Bitmap)MyClipboardObject.GetData(typeof(Bitmap)); //取出點陣圖

MyBitmap.Save("webcamPIC2.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

}

}

//-----------
}// public void CaptureA()



}// class CCapture
}
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 prague12 的頭像
    prague12

    prague12

    prague12 發表在 痞客邦 留言(0) 人氣()