Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys,
i'm having a nightmare with an application that is supposed to take a picture with a webcam. There is a 'Start Webcam' button on the form to open the camera to take a picture. Its event is OpenCamera() below:

VB
Private Sub OpenCamera()
        Dim iHeight As Integer = picCapture.Height
        Dim iWidth As Integer = picCapture.Width
        ' Open Preview window in picturebox .
        ' Create a child window with capCreateCaptureWindowA so you can display it in a picturebox.
        hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
            480, picCapture.Handle.ToInt32, 0)
        ' Connect to device
        If SendMessage(hHwnd, CAP_DRIVER_CONNECT, iDevice, 0) Then
            ' Set the preview scale
            SendMessage(hHwnd, CAP_SET_SCALE, True, 0)
            ' Set the preview rate in milliseconds
            SendMessage(hHwnd, CAP_SET_PREVIEWRATE, 66, 0)
            ' Start previewing the image from the camera
            SendMessage(hHwnd, CAP_SET_PREVIEW, True, 0)
            ' Resize window to fit in picturebox
            SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, _
                                   SWP_NOMOVE Or SWP_NOZORDER)
        Else
            ' Error connecting to device close window
            DestroyWindow(hHwnd)
        End If
    End Sub


Then, the form_closing event has the following:
VB
' Disconnect from device
       SendMessage(hHwnd, CAP_DRIVER_DISCONNECT, iDevice, 0)
       Clipboard.Clear()
       ' 'close window
       DestroyWindow(hHwnd)


This works fine only the first time the form is loaded. Any subsequent time requires pulling out the USB camera and reattaching it.
I've been on this for two weeks now with no solution. Please can anyone help me out here?

Thanx.
Posted

1 solution

WebCam With .Net[^]

This link must help you


Webcam DirectShow CP Article[^]
 
Share this answer
 
v2
Comments
Yosh_ 4-Apr-11 7:25am    
I'll check it out and get back to you. Thanx.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900