Library code snippets
Capture Video
By Alex , published on 21 Feb 2002
This program shows how to capture live video from a web cam and display it in a picture box.
Option Explicit
Const ws_visible = &H10000000
Const ws_child = &H40000000
Const WM_USER = 1024
Const WM_CAP_EDIT_COPY = WM_USER + 30
Const wm_cap_driver_connect = WM_USER + 10
Const wm_cap_set_preview = WM_USER + 50
Const wm_cap_set_overlay = WM_USER + 51
Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
Const WM_CAP_SEQUENCE = WM_USER + 62
Const WM_CAP_SINGLE_FRAME_OPEN = WM_USER + 70
Const WM_CAP_SINGLE_FRAME_CLOSE = WM_USER + 71
Const WM_CAP_SINGLE_FRAME = WM_USER + 72
Const DRV_USER = &H4000
Const DVM_DIALOG = DRV_USER + 100
Const PREVIEWRATE = 30
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Long, ByVal h As Integer) As Long
Dim hwndc As Long
Dim saveflag As Integer
Dim pictureindex As Integer
Dim filter1(-1 To 1, -1 To 1) As Single
Dim filter2(-1 To 1, -1 To 1) As Single
Dim temp As String
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
On Error GoTo handler:
hwndc = capCreateCaptureWindow("CaptureWindow", ws_child Or ws_visible, 0, 0, PichWnd.Width, PichWnd.Height, PichWnd.hWnd, 0)
If (hwndc <> 0) Then
temp = SendMessage(hwndc, wm_cap_driver_connect, 0, 0)
temp = SendMessage(hwndc, wm_cap_set_preview, 1, 0)
temp = SendMessage(hwndc, WM_CAP_SET_PREVIEWRATE, PREVIEWRATE, 0)
temp = SendMessage(Me.hWnd, WM_CAP_EDIT_COPY, 1, 0)
Picture1.Picture = Clipboard.GetData
Else
MsgBox "Unable to capture video.", vbCritical
End If
Exit Sub
handler:
End
End Sub
Related articles
Related discussion
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Here is some free source code for selecting the capture device http://ess-image.com/Graphic/Video/ListVideoSources_device.aspx
You may also like this http://ess-image.com/Graphic/Video/Vfw%20Conts.aspx its a list of const used with video for windows
If you need more help drop me a line on that site
!--removed tag-->hi Alex,
I want asp.net with vb coding for capture a image from webcam.
if u have that codes, can u send me to mail.my mail is(aralex19@gmail.com)
i hope i'll receive a mail from u soon,
thanks in advance.
regards
Alexisraj
So, dating back to 1988 (or so I assumed), VB.NET does allow these features but in Windows Vista and VB.NET (to VC#.NET interpreter language), I don't know why people are asking the same question. Webcam streaming works via the driver, not the port. So therefore the standard Windows Shell Dynamic Link Libraries (WSDLLs) channel the webcam stream via the registered key from the driver which is stored in the WSDLLs of which Visual Studio has full access of.
WSDLLs usually used the hWnd keys in the Operating System's registry. As webcams don't just work on the one operating system, most plug 'n' play webcams work on all OS' thus WSDLLs cannot work for webcams built on the Linux or Macintosh system.
But now, with the driver technology, WSDLLs and other Operating System System libraries are included on the webcam. But please make sure, if this problem ever was to occur, how come it worked with the standard capturing video in applications like Media Suites and Instant-Messenging? So you would guess with Visual Studio, the framework that defies all challenges would work? Please make sure the webcam has the Universal system for Windows, Mac and probably Linux.
I guess it would be easier to import the System Core Libraries (SCL) first before the class for easier access to the code.
Thus the sample provided is outdated. I would recommend this sample I found online (instead of writing my own), click here. If the link did not work, paste the following URL into your browser's address bar (that is if your machine isn't that ancient): http://www.devx.com/dotnet/Article/30375?type=kbArticle&trk=MSCP
So, dating back to 1988 (or so I assumed), VB.NET does allow these features but in Windows Vista and VB.NET (to VC#.NET interpreter language), I don't know why people are asking the same question. Webcam streaming works via the driver, not the port. So therefore the standard Windows Shell Dynamic Link Libraries (WSDLLs) channel the webcam stream via the registered key from the driver which is stored in the WSDLLs of which Visual Studio has full access of.
WSDLLs usually used the hWnd keys in the Operating System's registry. As webcams don't just work on the one operating system, most plug 'n' play webcams work on all OS' thus WSDLLs cannot work for webcams built on the Linux or Macintosh system.
But now, with the driver technology, WSDLLs and other Operating System System libraries are included on the webcam. But please make sure, if this problem ever was to occur, how come it worked with the standard capturing video in applications like Media Suites and Instant-Messenging? So you would guess with Visual Studio, the framework that defies all challenges would work? Please make sure the webcam has the Universal system for Windows, Mac and probably Linux.
I guess it would be easier to import the System Core Libraries (SCL) first before the class for easier access to the code.
Thus the sample provided is outdated. I would recommend this sample I found online (instead of writing my own), click here. If the link did not work, paste the following URL into your browser's address bar (that is if your machine isn't that ancient): http://www.devx.com/dotnet/Article/30375?type=kbArticle&trk=MSCP
Hello,
How do i open the dialogue box for cameras or scanner? and how can i open and view .tif image with VB codes.
Hope i can find the answers.
Hi,
I want to view live video from my home pc and web cam is installed in my office. So what should i do for? How can i view live video from a remote location?
Thanks and regards,
Wajid
I ask thesame thing
I know i have to do a server in my home pc, but how i get the video in my office...
this thing sure is applicable for security miscelaneus ^^
Hi,
I want to view live video from my home pc and web cam is installed in my office. So what should i do for? How can i view live video from a remote location?
Thanks and regards,
Wajid
I also want to know about video capturing using vb.net or in C#.
Thanks and Regards
Arasu.M
HEllo i just wanna ask... that when i am using the clipboard to diplay or to use the WEbcam.. whenever the webcam is on i cant COPY n PASTE anything else... Anything copied cannot be paste... because everytime the images are being copied and pasted in the picture box. How do i resolve this issue..?? so that anything else can also be copied and paste.
I have a problem
I am use avicap32.dll to capture images from Webcam,
My Question: When CaptureWindow is minimized, or dock using third party software then I noticed that the Captureto file does not work.
In summary, if capturewindow is minimized, or fully covered by another window, images are not captured.
Any help would be appreciated, but I am hoping that there is
some kind of workaround.
Regards..
Rushabh
downloaded the code was not able to get it to work in VB.Net. Any suggestions..
I have a creative labs NX Webcam.
Would like to feed my web cam images to a web page using asp.net.
Any help would be appreciated..
Al
I am trying to understand the functionnality of videocapture to clipboard... If my receiving binded picture box is hidden by another window, capture to clipboard does not update the clipboard...
Is this a clipboard issue or a picture box issue... Would anyone have a workaround?
I am trying to capture webcam screenshots every 30 seconds, but during this time I would like user to be able to
minimize application to work on another project like (MS Word, MS Project,....)
I have a problem and cannot figure out a workaround, possibly something to do with "overlay"...
I use avicap32.dll to capture images from Webcam,
SendMessage(Cam1Hwnd, WMCAPEDITCOPY, 0, 0)
'Clipboard.SetDataObject(SendMessage(Cam1Hwnd, WMCAPEDITCOPY, 0, 0))
'SendMessage(Cam1Hwnd, WMCAPGRABFRAMENOSTOP, 0, 0)
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
My Question: When CaptureWindow is minimized, or overlayed by another Window (from application or MS application) then I noticed that the Captureto Clipboard does not work, the clipboard gets updated only when
at least a fraction of the capture screen is visible.
In summary, if capturewindow is minimized, or fully covered by another window, images are not captured, but if only 2 lines (pixels) are visible, the whole capture window is copied correctly...
Any help would be appraciated, I read it might be a limitation of avicap32.dll, but I am hoping that there is
some kind of workaround.
Regards..
TWAIN is take more memory than wanted i think. sorry i don't know too much about it - just copied (and maybe slightly edited it), but i think mike is right, and you can change the hardware device by something like that.
Hi, why you don´t try using aTWAIN control in your aplication or usin Photoshop or any other digital aplication set up a defaut hardware... I think is better if use a TWAIN control in the code to switch diferent hardware..
I hope it help you
Greetings
Ladies n Gentlemen
I cam to this link in my effort to search for the way to capture images from digital cameras. I am interested in a way to be able to scan images and taking pictures from digital cameras and in some way have a control on the camera eg preview,zoom and take picture.
Sorry that I am not sure whether USB camera is also a digital camera and I can use the same code to talk to digital cameras.
Please if any body can help with this.
Why should we not as developers devote to finding out the solution to a thing like this and share it and enjoy the computing.
Amour
Dar Es Salaam
amourrashid@yahoo.com
Did you find a way to set the video driver during design time?
I'm with trouble which parameter it has to be changed. I didn'nt know how to do that.
My situation is that I have 2 cameras plugged into the usb, but it's only possible to get one camera, like you. If you can help me I will be grateful.
I am sending you an email.
Thank you
Could someone help me out with using CapGetDriverDescription in vb6 / vb.net?
I just get a false return from the call.
Brent
erm this is a bit old but ill reply 4 other people who may have same problems
temp = SendMessage(hwndc, wmcapdriverconnect, 0, 0) ' i belive will select default driver/device
temp = SendMessage(hwndc, wmcapdriverconnect, 1, 1) ' will set it to next device
temp = SendMessage(hwndc, wmcapdriver_connect, 2, 2) ' will set it to next next device lol
'and so on and so fourth
I need HELP!!! Ive been doin a VB application where Im connecting 2 Video Cameras at the same time.
I have no problem on connecting a single Camera, but with 2 Cameras simultaneously, Im gettin problems.
How can i set which driver should be used?
Ive been trying to change the index on the CapDriverConnect function but it still doesnt work!
The VideoSource Dialog keeps on showin up during runtime! How can I set the video driver
during design time?
Ive also been trying to change the Wparam, and Lparam of the WMCAPDRIVER_CONNECT message
but still cant set the appropriate index for the video driver!
PLEASE HELP!!! ANYBODY OUT THERE!! IM DESPARATE!
pls send me an email at: JSEspiritu@ayalasystems.com
THANK YOU!
I need HELP!!! Ive been doin a VB application where Im connecting 2 Video Cameras at the same time.
I have no problem on connecting a single Camera, but with 2 Cameras simultaneously, Im gettin problems.
How can i set which driver should be used?
Ive been trying to change the index on the CapDriverConnect function but it still doesnt work!
The VideoSource Dialog keeps on showin up during runtime! How can I set the video driver
during design time?
Ive also been trying to change the Wparam, and Lparam of the WMCAPDRIVER_CONNECT message
but still cant set the appropriate index for the video driver!
PLEASE HELP!!! ANYBODY OUT THERE!! IM DESPARATE!
pls send me an email at: JSEspiritu@ayalasystems.com
THANK YOU!
I happen to have a 3dfx tv tuner card with capture, and that's what shows up when I try the code.
What should I change in it so that I can capture from my usb cam instead of the tv tuner?email me
I happen to have a 3dfx tv tuner card with capture, and that's what shows up when I try the code.
What should I change in it so that I can capture from my usb cam instead of the tv tuner?3x@sympatico.ca">You can also e-mail meif you want!
This thread is for discussions of Capture Video.