


版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、using System;using System.Collections.Generic;using System.Comp onen tModel;using System.Data;using System.Drawing;using Syste m丄 i nq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;n amespaceWi ndowsFormsApplicatio n24public partial class Form1 : Formpublic Form1(
2、)In itializeComp onen t();const short WM_CAP =1024;const int WM_CAP_DRIVER_CONNECT = WM_CAP +const int WM_CAP_DRIVER_DISCONNECT = WM_CAP +const int WM_CAP_EDIT_COPY = WM_CA30+con st int WM_CAP_SET_PREVIEW = WM_C庖0; +const int WM_CAP_SET_PREVIEWRATE = WM_G5®P +const int WM_CAP_SET_SCALE = WM_CAJ
3、3;+con st int WS_CHILD = 1073741824const int WS_VISIBLE = 268435456con st short SWP_NOMOVE2=con st short SWP_NOSIZE =1;const short SWP_NOZORDEF4=const short HWND_BOTTOM1 =int iDevice =0;int hHwnd;System.Runtime.InteropServices.Dlllmport("user32" , EntryPoi nt 二"Se ndMessageA"stat
4、ic extern int SendMessage(int hwnd, int wMsg, int wParam, MarshalAs(U nman agedType.AsA ny)object lParam);System.Runtime.InteropServices.Dlllmport("user32" , EntryPoi nt 二"SetWi ndowPos")static extern int SetWindowPos( int hwnd, int hWndlnsertAfter, int x, int y, int cx, int cy,
5、int wFlags);System.Runtime.lnteropServices.Dlllmport("user32")static extern bool DestroyWindow( int hndw);System.R un time.I nteropServices.Dlllmport("avicap32.dll")static extern int capCreateCaptureWindowA( string lpszWi ndowName,int dwStyle, int x, int y, int nWidth, short nHei
6、ght, int hWndParent, int nID);System.R un time.I nteropServices.Dlllmport("avicap32.dll")static extern bool capGetDriverDescriptionA(short wDriver, string lpszName, int cbName, string lpszVer, int cbVer);private void OpenPreviewWindow()int iHeight =320;int iWidth =200;/ Ope n Preview wi nd
7、ow in picturebox/hHw nd = capCreateCaptureWi ndowA(iDevice.ToStri ng(),n t32(),0);/ Connect to device/if (SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) = 1)/ Set the preview scale/SendMessage(hHwnd, WM_CAP_SET_SCALE,1, 0);/ Set the preview rate in milliseco nds/Sen dMessage(hHw nd, WM_CAP_SE
8、T_PREVIEWRATE,66,0);/ Start preview ing the image from the camera/SendMessage(hHwnd, WM_CAP_SET_PREVIEW,1, 0);/ Resize win dow to fit in picturebox/0, 0, iWidth,SetWi ndowPos(hHw nd, HWND_BOTTOM,iHeight, (SWP_NOMOVE | SWP_NOZORDER);else/ Error connecting to device close wi ndow/DestroyWi ndow(hHw nd
9、);private void ClosePreviewWindow()/ Disc onn ect from device/Sen dMessage(hHw nd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0);/ close win dow/DestroyWi ndow(hHw nd);private void butt on 1_Click( object sen der, Eve ntArgs e)iDevice =int .Parse(device_number_textBox.Text);Ope nPreviewWi ndow();C# codeusin
10、g System;using System.Collections.Generic;using System.Comp onen tModel;using System.Data;using System.Drawing;using Syste m丄 i nq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;n amespaceWi ndowsFormsApplicatio n24public partial class Form1 : Formpublic Form1()In
11、itializeComp onen t();const short WM_CAP =1024;WM_CAP +=WM_CAP +const int WM_CAP_DRIVER_CONNECT =const int WM_CAP_DRIVER_DISCONNECT const int WM_CAP_EDIT_COPY = WM_CA30+con st int WM_CAP_SET_PREVIEW = WM_C庖0; + const int WM_CAP_SET_PREVIEWRATE = WM_C2P + const int WM_CAP_SET_SCALE = WM_CAJ3;+con st
12、int WS_CHILD = 1073741824const int WS_VISIBLE = 268435456con st short SWP_NOMOVE2=con st short SWP_NOSIZE =1;const short SWP_NOZORDER4=const short HWND_BOTTOM1 =int iDevice =0;int hHwnd;System.Runtime.InteropServices.Dlllmport("user32" , EntryPoi nt ="Se ndMessageA"static extern
13、int SendMessage(int hwnd, int wMsg, int wParam, MarshalAs(U nman agedType.AsA ny)object lParam);System.Runtime.InteropServices.Dlllmport("user32" , EntryPoi nt ="SetWi ndowPos")static extern int SetWindowPos( int hwnd, int hWndlnsert After, int x, int y, int cx, int cy, int wFlag
14、s);System.Runtime.lnteropServices.Dlllmport("user32")static extern bool DestroyWindow( int hndw);System.R un time.I nteropServices.Dlllmport("avicap32.dll")static extern int capCreateCaptureWindowA( string lpszWi ndowName,int dwStyle, int x, int y, int nWidth, short nHeight, int
15、hWndParent, int nID);System.R un timenteropServices.Dlllmport("avicap32.dll")static extern bool capGetDriverDescriptionA(short wDriver, string lpszName, int cbName, string lpszVer, int cbVer);private void OpenPreviewWindow()int iHeight =320;int iWidth =200;/ Ope n Preview wi ndow in pictur
16、ebox/hHw nd = capCreateCaptureWi ndowA(iDevice.ToStri ng(),n t32(),0);/ Connect to device/if (SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) = 1)/ Set the preview scale/SendMessage(hHwnd, WM_CAP_SET_SCALE,1, 0);/ Set the preview rate in milliseco nds/Sen dMessage(hHw nd, WM_CAP_SET_PREVIEWRAT
17、E,66,/ Start preview ing the image from the camera/SendMessage(hHwnd, WM_CAP_SET_PREVIEW,1, 0);/ Resize win dow to fit in picturebox/SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, iWidth,iHeight, (SWP_NOMOVE | SWP_NOZORDER);else/ Error connecting to device close wi ndow/DestroyWi ndow(hHw nd);private void ClosePreviewWindow()/ Disc onn ect from device/Sen dMessage(hHw nd, WM_CAP_DRIVER_DISCONNECT, iDevic e, 0);/ close win dow/DestroyWi ndow(hHw
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 私人房租抵押協議書
- 燈會合作合同協議書
- 狗狗麻醉手術協議書
- 離婚陪嫁分割協議書
- 清償欠薪責任協議書
- 電梯破門救援協議書
- 自愿放棄婚姻協議書
- 種植藥材公司協議書
- 糧油市場招商協議書
- 電焊作業免責協議書
- 2025重慶武工工業技術研究院有限公司招聘15人筆試參考題庫附帶答案詳解
- 輸液導管相關靜脈血栓形成中國專家共識 課件
- 光伏電站面試題庫及答案
- 2024年泉州實驗中學初一新生入學考試數學試卷
- 車間技能矩陣管理制度
- 陶藝店管理制度
- 2025-2030中國儲能電站行業市場深度分析及前景趨勢與投資研究報告
- 2025年標準租房合同范本
- AI在財務管理中的應用策略研究
- 三元空間下個人化IP綜藝《燦爛的花園》敘事與價值研究
- 2025屆安徽省池州市普通高中高三教學質量統一監測政治試卷含、答案
評論
0/150
提交評論