Page 1 of 1

taking pictures with webcam?

Posted: Wed May 08, 2013 8:56 pm
by Livengood
does anyone know how to get a webcam to take photos

Re: taking pictures with webcam?

Posted: Wed May 08, 2013 10:12 pm
by noypikami
take a look on this topic, this can help you....
viewtopic.php?f=131&t=9947

Re: taking pictures with webcam?

Posted: Thu May 09, 2013 2:34 am
by Shim
i think this is what you need
Code: Select all
Dim loSnap As New WebcamSnap 
loSnap.TakePicture(0)


The devices collection shows a list of all webcam devices on your machine so you can populate a combo with them.

Note: This example has no decent error handling, which I suspect will be needed in the “real world” of multiple devices.

Here’s the WebcamSnap class:


Option Explicit On 
Imports System.IO 
Imports System.Runtime.InteropServices 

Public Class Webcam
    Const WM_CAP As Short = &H400S

    Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10 
    Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11 
    Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30 
    Const WS_CHILD As Integer = &H40000000 
    Const WS_VISIBLE As Integer = &H10000000 
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ 
        (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _ 
        <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer

    Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _ 
        (ByVal lpszWindowName As String, ByVal dwStyle As Integer, _ 
        ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _ 
        ByVal nHeight As Short, ByVal hWndParent As Integer, _ 
        ByVal nID As Integer) As Integer

    Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _ 
        ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _ 
        ByVal cbVer As Integer) As Boolean

    Public Devices As New List(Of String) 
    Public Height As Integer = 480 
    Public Width As Integer = 640 
    Public OutputPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) 
    Public FilenamePrefix As String = "snapshot" 
    Public Sub New() 
        mLoadDeviceList() 
    End Sub 
    Private Sub mLoadDeviceList() 
        Dim lsName As String = Space(100) 
        Dim lsVers As String = Space(100) 
        Dim lbReturn As Boolean 
        Dim x As Integer = 0

        Do 
            '   Get Driver name and version 
            lbReturn = capGetDriverDescriptionA(x, lsName, 100, lsVers, 100)

            ' If there was a device add device name to the list 
            If lbReturn Then Devices.Add(lsName.Trim) 
            x += 1 
        Loop Until lbReturn = False 
    End Sub 
    Public Sub TakePicture() 
        For i = 0 To Me.Devices.Count - 1 
            Dim lsFilename As String = Path.Combine(OutputPath, Me.FilenamePrefix & i & ".jpg") 
            TakePicture(i, lsFilename) 
        Next 
    End Sub 
    Public Sub TakePicture(ByVal iDevice As Integer) 
        Me.TakePicture(iDevice, Path.Combine(OutputPath, Me.FilenamePrefix & ".jpg")) 
    End Sub 
    Public Sub TakePicture(ByVal iDevice As Integer, ByVal filename As String)

        Dim lhHwnd As Integer ' Handle to preview window

        ' Create a form to play with 
        Using loWindow As New System.Windows.Forms.Form

            ' Create capture window 
            lhHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, Me.Width, _ 
               Me.Height, loWindow.Handle.ToInt32, 0)

            ' Hook up the device 
            SendMessage(lhHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) 
            ' Allow the webcam apeture to let enough light in 
            For i = 1 To 10 
                Application.DoEvents() 
            Next

            ' Copy image to clipboard 
            SendMessage(lhHwnd, WM_CAP_EDIT_COPY, 0, 0)

            ' Get image from clipboard and convert it to a bitmap 
            Dim loData As IDataObject = Clipboard.GetDataObject() 
            If loData.GetDataPresent(GetType(System.Drawing.Bitmap)) Then 
                Using loBitmap As Image = CType(loData.GetData(GetType(System.Drawing.Bitmap)), Image) 
                    loBitmap.Save(filename, Imaging.ImageFormat.Jpeg) 
                End Using 
            End If

            SendMessage(lhHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)

        End Using

    End Sub

End Class

source - http://www.experts-exchange.com/Program ... 82234.html

you can also use this library http://easywebcam.codeplex.com/

-shim

Re: taking pictures with webcam?

Posted: Thu May 09, 2013 6:06 am
by Livengood
na, i ended up find a newer source. All the others are out dated. As far as i have looked at them the tutorials and codes work it just wont connect to the cam.