大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> Delphi编程控制摄像头

Delphi编程控制摄像头

时间: 2021-07-31 作者:daque

你的电脑有没有摄像头?看到旁人用qq玩视屏你会不会去想如何实行的?这边引见运用delphi运用ms的avicap32.dll就可轻快的实行对摄像头编制程序,即使再加上你的搜集编制程序程度,实行一个视屏谈天就不可什么题目了。看看底下代码的代码:const wm_cap_start = wm_user;const wm_cap_stop = wm_cap_start + 68;const wm_cap_driver_connect = wm_cap_start + 10;const wm_cap_driver_disconnect = wm_cap_start + 11;const wm_cap_savedib = wm_cap_start + 25;const wm_cap_grab_frame = wm_cap_start + 60;const wm_cap_sequence = wm_cap_start + 62;const wm_cap_file_set_capture_filea = wm_cap_start + 20;const wm_cap_sequence_nofile =wm_cap_start+ 63 const wm_cap_set_overlay =wm_cap_start+ 51 const wm_cap_set_preview =wm_cap_start+ 50 const wm_cap_set_callback_videostream = wm_cap_start +6;const wm_cap_set_callback_error=wm_cap_start +2;const wm_cap_set_callback_statusa= wm_cap_start +3;const wm_cap_set_callback_frame= wm_cap_start +5;const wm_cap_set_scale=wm_cap_start+ 53 const wm_cap_set_previewrate=wm_cap_start+ 52 function capcreatecapturewindowa(lpszwindowname : pchar; dwstyle : longint; x : integer;y : integer;nwidth : integer;nheight : integer;parentwin : hwnd;nid : integer): hwnd;stdcall external ‘avicap32.dll‘;上头的代码即是咱们重要用到的一个因变量和恒量的设置。好了,翻开你的delphi,兴建一个工程,将上头的设置加上吧。兴建一个窗口,放个panel上去,增添一个按钮,caption树立为"发端"这边须要设置一个全部变量,var hwndc : thandle;发端按钮代码如次:beginhwndc := capcreatecapturewindowa(‘my own capture window‘,ws_child or ws_visible ,panel1.left,panel1.top,panel1.width,panel1.height,form1.handle,0);hwndc := capcreatecapturewindowa(‘my own capture window‘,ws_child or ws_visible ,panel1.left,panel1.top,panel1.width,panel1.height,form1.handle,0);if hwndc <> 0 then beginsendmessage(hwndc, wm_cap_set_callback_videostream, 0, 0);sendmessage(hwndc, wm_cap_set_callback_error, 0, 0);sendmessage(hwndc, wm_cap_set_callback_statusa, 0, 0);sendmessage(hwndc, wm_cap_driver_connect, 0, 0);sendmessage(hwndc, wm_cap_set_scale, 1, 0);sendmessage(hwndc, wm_cap_set_previewrate, 66, 0);sendmessage(hwndc, wm_cap_set_overlay, 1, 0);sendmessage(hwndc, wm_cap_set_preview, 1, 0);end;按f9运转一下,如何样,是否不妨看到摄像头的视屏了?那如何停下来?再加个按钮caption树立成"遏止"代码如次:if hwndc <> 0 then beginsendmessage(hwndc, wm_cap_driver_disconnect, 0, 0);hwndc := 0;end;视屏截到了,如何把它给生存下来呢?底下按两种办法生存,一个是bmp静态图,一个是avi动画。再放三个按钮到窗体上去,caption辨别树立成"生存bmp"、"发端录像"、"遏止录像"三个按钮的代码辨别如次://生存bmpif hwndc <> 0 then beginsendmessage(hwndc,wm_cap_savedib,0,longint(pchar(‘c:\\test.bmp‘)));end;//发端录像if hwndc <> 0 thenbeginsendmessage(hwndc,wm_cap_file_set_capture_filea,0, longint(pchar(‘c:\\test.avi‘)));sendmessage(hwndc, wm_cap_sequence, 0, 0);end;//遏止录像if hwndc <> 0 then beginsendmessage(hwndc, wm_cap_stop, 0, 0);end;再运转看看吧。。不妨生存几张图看看,也不妨录成avi此后渐渐观赏。步调运转功效: [ 关系贴图 ]http://yousoft.hi.com.cn/upload/forum/2004715161959.jpg完备的步调代码如次:unit unit1;interfaceuseswindows, messages, sysutils, variants, classes, graphics, controls, forms,dialogs, stdctrls, extctrls;typetform1 = class(tform)panel1: tpanel;button1: tbutton;button2: tbutton;button3: tbutton;button4: tbutton;button5: tbutton;procedure button1click(sender: tobject);procedure button2click(sender: tobject);procedure button3click(sender: tobject);procedure button4click(sender: tobject);procedure button5click(sender: tobject);procedure formclose(sender: tobject; var action: tcloseaction);privatehwndc : thandle;public{ public declarations }end;varform1: tform1;const wm_cap_start = wm_user;const wm_cap_stop = wm_cap_start + 68;const wm_cap_driver_connect = wm_cap_start + 10;const wm_cap_driver_disconnect = wm_cap_start + 11;const wm_cap_savedib = wm_cap_start + 25;const wm_cap_grab_frame = wm_cap_start + 60;const wm_cap_sequence = wm_cap_start + 62;const wm_cap_file_set_capture_filea = wm_cap_start + 20;const wm_cap_sequence_nofile =wm_cap_start+ 63 const wm_cap_set_overlay =wm_cap_start+ 51 const wm_cap_set_preview =wm_cap_start+ 50 const wm_cap_set_callback_videostream = wm_cap_start +6;const wm_cap_set_callback_error=wm_cap_start +2;const wm_cap_set_callback_statusa= wm_cap_start +3;const wm_cap_set_callback_frame= wm_cap_start +5;const wm_cap_set_scale=wm_cap_start+ 53 const wm_cap_set_previewrate=wm_cap_start+ 52 function capcreatecapturewindowa(lpszwindowname : pchar;dwstyle : longint;x : integer;y : integer;nwidth : integer;nheight : integer;parentwin : hwnd;nid : integer): hwnd;stdcall external ‘avicap32.dll‘;implementation{$r *.dfm}procedure tform1.button1click(sender: tobject);beginhwndc := capcreatecapturewindowa(‘my own capture window‘,ws_child or ws_visible ,panel1.left,panel1.top,panel1.width,panel1.height,form1.handle,0);hwndc := capcreatecapturewindowa(‘my own capture window‘,ws_child or ws_visible ,panel1.left,panel1.top,panel1.width,panel1.height,form1.handle,0);if hwndc <> 0 then beginsendmessage(hwndc, wm_cap_set_callback_videostream, 0, 0);sendmessage(hwndc, wm_cap_set_callback_error, 0, 0);sendmessage(hwndc, wm_cap_set_callback_statusa, 0, 0);sendmessage(hwndc, wm_cap_driver_connect, 0, 0);sendmessage(hwndc, wm_cap_set_scale, 1, 0);sendmessage(hwndc, wm_cap_set_previewrate, 66, 0);sendmessage(hwndc, wm_cap_set_overlay, 1, 0);sendmessage(hwndc, wm_cap_set_preview, 1, 0);end;end;procedure tform1.button2click(sender: tobject);beginif hwndc <> 0 then beginsendmessage(hwndc, wm_cap_driver_disconnect, 0, 0);hwndc := 0;end;end;procedure tform1.button3click(sender: tobject);beginif hwndc <> 0 then beginsendmessage(hwndc,wm_cap_savedib,0,longint(pchar(‘c:\\test.bmp‘)));end;end;procedure tform1.button4click(sender: tobject);beginif hwndc <> 0 thenbeginsendmessage(hwndc,wm_cap_file_set_capture_filea,0, longint(pchar(‘c:\\test.avi‘)));sendmessage(hwndc, wm_cap_sequence, 0, 0);end;end;procedure tform1.button5click(sender: tobject);beginif hwndc <> 0 then beginsendmessage(hwndc, wm_cap_stop, 0, 0);end;end;procedure tform1.formclose(sender: tobject; var action: tcloseaction);beginif hwndc <> 0 then beginsendmessage(hwndc, wm_cap_driver_disconnect, 0, 0);end;end;end.即使电脑没有摄像头,但又想看看步调的功效,不妨么?呵呵,固然不妨,找个假造摄像头不就搞定,大师不妨试试softcam这个软硬件,它是一个表里如一的软硬件摄像机,能模仿变成“如实的”摄像机,指示一下诸位,大师可不要用这个东东用在qq,msn等谈天软硬件上捉弄mm或gg啊。对于摄像头编制程序,大师也不妨看看这组vcl组件:dspack,dspack是一套运用微软direct show和directx本领的类和组件,安排处事于directx 9,扶助体例win9x, me, 2000和windows xp。好了,就引见那些了,至于视屏谈天如何实行,就看你的了,无非是按数据收缩传输给对方,表露出来,然而话又说回顾,看似大略,实行起来再有些难度的。

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.