Вы находитесь на странице: 1из 4

CAPTURAR WEBCAM CON VB.

NET
Que haremos? Crearemos una aplicacin en Visual Stu io! la cual "ar# uso e una $e%cam para capturar el &i eo en 'rames in epen ientes ( epositarlos en memoria para espues mostralos al usuario a tra&)s e un picture%o* ( un Timer para crear la ilusin e mo&imiento. Porque lo haremos? Por+ue es ,usto ( necesario Que necesitamos? Visual Stu io -../ o Superior We%cam 01o utili2o una 3elu*4 Conocimientos interme ios so%re Visual Basic Un repaso so%re las li%rer5as e $in o$s! prep#rese para su'rir Si a6n te 'alta un po+uito so%re las 377! lee al 8U977E :rame$or; .NET <.= o superior Comencemos >. Crea un nue&o pro(ecto en VS! a?a e una nue&a clase 0 WebCam.vb4! al :orm> +ue te crea por e'ecto! a?a e tres %otones! un PictureBo* ( un Timer como muestra la si@uiente ima@enA

-. 7a clase WebCam.vb! es la encar@a a e reali2ar to o el tra%a,o! esta importar# li%rer5as 377 propias e Win o$s! a emas implementa 'unciones para comen2ar el ispositi&o! etenerlo ( tam%i)n una 'uncin para capturar 'rames ( colocarlas en un picture%o* Imports System.Runtime.InteropServices Public Class WebCam Dim CapHwnd As Integer ' ama!o de la ventana del webcam

Dim Anc"o As Integer # $%& Dim Alto As Integer # %'& '(libreria.D))( # *l nombre del API +ue se desea importar ' *ntryPoint # indica el nombre e,acto de la -unci.n del API +ue +ueremos usar /Region ()ibrerias D))( ')a -unci.n Send0essage llama al procedimiento de ventana para la ventana especi-icada y no vuelve "asta +ue el procedimiento de ventana se "a procesado el mensa1e ')R*S2) Send0essage3 'HW4D "Wnd5 66 "andle o- destination window '2I4 0sg5 66 message to send 'WPARA0 wParam5 66 -irst message parameter ')PARA0 lParam 66 second message parameter '78 9DllImport3(user$%.dll(5 *ntryPoint:#(Send0essage(7; < Public S"ared =unction Send0essage3>y?al "Wnd As Integer5 >y?al 0sg As 2Integer5 >y?al wParam As Integer5 >y?al lParam As Integer7 As Integer *nd =unction 'Crea una ventana de captura 9DllImport3(avicap$%.dll(5 *ntryPoint:#(capCreateCaptureWindowA(7; < Public S"ared =unction capCreateCaptureWindowA3>y?al 4ombre As String5 >y?al dwStyle As Integer5 >y?al @ As Integer5 >y?al A As Integer5 >y?al nWidt" As Integer5 >y?al nHeig"t As Integer5 >y?al "Wnd As Integer5 >y?al nID As Integer7 As Integer *nd =unction /*nd Region /Region (Constantes API B no se +ue signi-ican todas ( Const W0<2S*R As Integer # C&%' Const W0<CAP<CD44*C As Integer # C&$' Const W0<CAP<DISCD44*C As Integer # C&$E Const W0<CAP<F* <=RA0* As Integer # C&G' Const W0<CAP<CDPA As Integer # C&E' Const W0<CAP<S AR As Integer # W0<2S*R Const W0<CAP<S* <PR*?I*WRA * As Integer # W0<2S*R H E% Const W0<CAP<D)F<?ID*D=DR0A As Integer # W0<CAP<S AR H 'C Const W0<CAP<D)F<?ID*DSD2RC* As Integer # W0<CAP<S AR H '% Const W0<CAP<D)F<?ID*DDISP)AA As Integer # W0<CAP<S AR H '$ Const W0<CAP<F* <?ID*D=DR0A As Integer # W0<CAP<S AR H '' Const W0<CAP<S* <?ID*D=DR0A As Integer # W0<CAP<S AR H 'E Const W0<CAP<D)F<?ID*DCD0PR*SSID4 As Integer # W0<CAP<S AR H 'I Const W0<CAP<S* <PR*?I*W As Integer # W0<CAP<S AR H E& /*nd Region 'Captura -rame y deposita en el portapapeles Public Sub timer<ticJ3>y?al picture As Picture>o,7 Send0essage3CapHwnd5 W0<CAP<F* <=RA0*5 &5 &7 Send0essage3CapHwnd5 W0<CAP<CDPA5 &5 &7 picture.Image # Clipboard.FetImage37 Application.Do*vents37 *nd Sub 'guarda el -rame +ue esta en memoria en un arc"ivo KPF Public Sub Capturar3>y?al picture As Picture>o,7 Dim s-ile<KPF As String # (e:Larc"ivo.1pg( Dim ob1<bit0ap As 4ew >itmap3Anc"o5 Alto7 ry picture.Draw o>itmap3ob1<bit0ap5 4ew Rectangle3&5 &5 Anc"o5 Alto77 ob1<bit0ap.Save3s-ile<KPF5 Imaging.Image=ormat.Kpeg7 0essage>o,.S"ow3(Imagen capturada en M( N s-ile<KPF N ( O(7 Catc" e, As *,ception System.Console.Write)ine3e,7 *nd ry *nd Sub

&7

Public Sub Iniciar3>y?al timer As imer5 >y?al padre As =orm7 ry 'Con-igura la ventana de captura CapHwnd # capCreateCaptureWindowA3(WebCam(5 &5 &5 &5 Anc"o5 Alto5 padre.Handle. oInt$%375 Application.Do*vents37 Send0essage3CapHwnd5 W0<CAP<CD44*C 5 &5 &7 Send0essage3CapHwnd5 W0<CAP<S* <PR*?I*WRA *5 IP5 &7 Send0essage3CapHwnd5 W0<CAP<S* <PR*?I*W5 &5 &7 'se inicia el imer timer.Start37 Catc" e, As *,ception Console.Write)ine3e,7 *nd ry *nd Sub Public Sub Detener3>y?al timer As imer7 ry timer.Stop37 Application.Do*vents37 Send0essage3CapHwnd5 W0<CAP<DISCD44*C 5 &5 &7 Catc" e, As *,ception Console.Write)ine3e,7 *nd ry *nd Sub

*nd Class <. 3e%emos implementar la clase We%Cam.&% ( sus 'unciones en el :orm>.&%! el c i@o esA Public Class =ormC Dim webcam As 4ew WebCam Private Sub imerC< icJ3>y?al sender As System.Db1ect5 >y?al e As System.*ventArgs7 Handles imerC. icJ webcam.timer<ticJ3Picture>o,C7 *nd Sub Private Sub >uttonC<ClicJ3>y?al sender As System.Db1ect5 >y?al e As System.*ventArgs7 Handles >uttonC.ClicJ webcam.Iniciar3 imerC5 0e7 *nd Sub Private Sub >utton%<ClicJ3>y?al sender As System.Db1ect5 >y?al e As System.*ventArgs7 Handles >utton%.ClicJ webcam.Detener3 imerC7 *nd Sub Private Sub >utton$<ClicJ3>y?al sender As System.Db1ect5 >y?al e As System.*ventArgs7 Handles >utton$.ClicJ webcam.Capturar3Picture>o,C7 *nd Sub *nd Class =. Terminamos! @uar amos el pro(ecto! re2amos un poco ( presionamos :=! lo el re2o es por+ue con $in o$s nunca se sa%e lo +ue pue e pasar

WebCam 2008 HERE (el archivo tcam!

P"#$ RE%&C'"(&)"#

Proyecto de base de datos Firebird VB Creacin de GUI con Matlab GUIDE Ejecutar JAR desde Visual Basic !E" #$an%adores& JC'ec(Bo) dentro J"able con !etbeans J"able editable con base de datos

Вам также может понравиться