taking pictures with webcam?

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 445
Joined: Tue Feb 16, 2010 6:24 am

taking pictures with webcam?
Livengood
does anyone know how to get a webcam to take photos
Image
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

Re: taking pictures with webcam?
noypikami
take a look on this topic, this can help you....
viewtopic.php?f=131&t=9947
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: taking pictures with webcam?
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
Find my programs on Softpedia
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 445
Joined: Tue Feb 16, 2010 6:24 am

Re: taking pictures with webcam?
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.
Image
4 posts Page 1 of 1
Return to “Tutorial Requests”