Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 14:55

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[VB.NET] Webcam Programm Problem

Discussion on [VB.NET] Webcam Programm Problem within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Feb 2013
Posts: 62
Received Thanks: 5
[VB.NET] Webcam Programm Problem

Hey Zusammen!

Ich arbeite im Moment an einem Programm dass das Bild der Webcam in einer PictureBox anzeigt und es speichern soll.

Mit Hilfe der avicap32.dll hab ich's geschafft dass das Bild meiner Webcam angezeigt wird aber hat jemand eine Idee wie Ich dass in eine Datei speichern könnte?

Hier ist mein Code:

Code:
Public Class Form1
    Dim videoHandle As IntPtr
    Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Declare Auto Function capCreateCaptureWindow Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As Short, ByVal y As Integer, ByVal nWidth As Short, ByVal nHeight As Short, ByVal hWndParent As IntPtr, ByVal nID As Byte) As IntPtr

    Const EM_LINEFROMCHAR As Integer = &HC9
    Const EM_LINEINDEX As Integer = &HBB

    Const WS_CHILD As Integer = &H40000000
    Const WS_VISIBLE As Integer = &H10000000

    Const WM_USER As Short = &H400S
    Const WM_CAP_START As Short = &H400S
    Const WM_CAP_EDIT_COPY As Short = WM_CAP_START + 30
    Const WM_CAP_DRIVER_CONNECT As Short = WM_CAP_START + 10
    Const WM_CAP_SET_PREVIEWRATE As Short = WM_CAP_START + 52
    Const WM_CAP_SET_OVERLAY As Short = WM_CAP_START + 51
    Const WM_CAP_SET_PREVIEW As Short = WM_CAP_START + 50
    Const WM_CAP_DRIVER_DISCONNECT As Short = WM_CAP_START + 11

    Function CreateCaptureWindow(ByRef hWndParent As IntPtr, Optional ByRef x As Short = 0, Optional ByRef y As Short = 0, Optional ByRef nWidth As Short = 640, Optional ByRef nHeight As Short = 420, Optional ByRef nCameraID As Integer = 0) As IntPtr
        Dim previewHandle As IntPtr

        previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, x, y, nWidth, nHeight, hWndParent, 1)
        SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
        SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 30, 0)
        SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
        SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)

        Return previewHandle
    End Function

    Sub Disconnect(ByRef nCaptureHandle As IntPtr, Optional ByRef nCameraID As Integer = 0)
        SendMessage(nCaptureHandle, WM_CAP_DRIVER_DISCONNECT, nCameraID, 0)
    End Sub

    Sub Form2_FormClosing() Handles Me.FormClosing
        Me.Disconnect(videoHandle)
    End Sub

    Sub Button1_Click() Handles Button1.Click
        videoHandle = Me.CreateCaptureWindow(PictureBox1.Handle)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.Disconnect(videoHandle)
    End Sub
End Class
TheBeanjay is offline  
Old 11/03/2013, 21:37   #2

 
Ravenstorm's Avatar
 
elite*gold: 0
The Black Market: 100/0/0
Join Date: Jan 2010
Posts: 13,150
Received Thanks: 3,206
Einfach eine neue Funktion für das Speichern des Bilds aus der PictureBox deklarieren:

Code:
Private Sub Bild_Speichern()
        Try
            If (pictureBox1 IsNot Nothing) Then
                Dim dateiPfad As String = "C:\User\Desktop"
                Dim bm As Bitmap = pictureBox1 .Image
                bm.Save(dateiPfad & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
            End If
        Catch ex As Exception
            MessageBox.Show("Bild Wurde nicht gespeichert.", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
Bin mir nicht sicher ob die Funktion genau so richtig war, allerdings ist das die Standardvorgehensweise.
Ravenstorm is offline  
Old 11/03/2013, 21:41   #3
 
elite*gold: 0
Join Date: Feb 2013
Posts: 62
Received Thanks: 5
Quote:
Originally Posted by Ravenstorm View Post
Einfach eine neue Funktion für das Speichern des Bilds aus der PictureBox deklarieren:

Code:
Private Sub Bild_Speichern()
        Try
            If (pictureBox1 IsNot Nothing) Then
                Dim dateiPfad As String = "C:\User\Desktop"
                Dim bm As Bitmap = pictureBox1 .Image
                bm.Save(dateiPfad & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
            End If
        Catch ex As Exception
            MessageBox.Show("Bild Wurde nicht gespeichert.", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
Bin mir nicht sicher ob die Funktion genau so richtig war, allerdings ist das die Standardvorgehensweise.
Ja aber ich will ja nicht ein Bild sondern ein Video wäre super ^^ Weil in meiner Picture Box ist ja auch nicht nur ein Bild sondern ein Preview der Webcam ^^ Also als Video nicht als Bild und jetzt ist nur die Frage wie ich dass speichern kann
TheBeanjay is offline  
Old 11/03/2013, 21:44   #4
 
tolio's Avatar
 
elite*gold: 2932
The Black Market: 169/1/0
Join Date: Oct 2009
Posts: 6,966
Received Thanks: 1,097
ein video ist nichts anderes als eine folge von bildern. ne direkte funktion das als video zu speichern ist mir nicht bekannt
tolio is offline  
Old 11/03/2013, 21:45   #5
 
elite*gold: 0
Join Date: Feb 2013
Posts: 62
Received Thanks: 5
Kann man denn diese Vielen Bilder in ein Video zusammenfassen oder so? Damit ich am Ende des Tages ein Video und nicht 1000 Bilder habe?
TheBeanjay is offline  
Old 11/03/2013, 21:46   #6

 
Ravenstorm's Avatar
 
elite*gold: 0
The Black Market: 100/0/0
Join Date: Jan 2010
Posts: 13,150
Received Thanks: 3,206
Quote:
Originally Posted by tolio View Post
ein video ist nichts anderes als eine folge von bildern. ne direkte funktion das als video zu speichern ist mir nicht bekannt
Ja vorallem weil er ist eine PictureBox schreibt... Es gab aber mal eine Libary die hat irgendwas in der Art gemacht von wegen Screens -> Video... Muss mich mal auf die Suche machen...
Ravenstorm is offline  
Old 11/03/2013, 21:49   #7
 
elite*gold: 0
Join Date: Feb 2013
Posts: 62
Received Thanks: 5
Quote:
Originally Posted by Ravenstorm View Post
Ja vorallem weil er ist eine PictureBox schreibt... Es gab aber mal eine Libary die hat irgendwas in der Art gemacht von wegen Screens -> Video... Muss mich mal auf die Suche machen...
Das wär echt super nett ich hab auch gegooglet aber nichts gefunden ^^ Ich hoffe mal jemand der sich in VB.NET besser auskennt als Ich findet da was!
TheBeanjay is offline  
Old 11/03/2013, 21:52   #8
 
tolio's Avatar
 
elite*gold: 2932
The Black Market: 169/1/0
Join Date: Oct 2009
Posts: 6,966
Received Thanks: 1,097
ich hab grad mal "https://www.google.de/#q=vb.net+capture+webcam+video" gegooglet, da kommen dutzende sources...
tolio is offline  
Old 11/03/2013, 21:54   #9
 
Frosttall's Avatar
 
elite*gold: 55
Join Date: Oct 2009
Posts: 5,471
Received Thanks: 1,479



Die Library die du benötigst:
Frosttall is offline  
Old 11/03/2013, 21:56   #10
 
elite*gold: 0
Join Date: Feb 2013
Posts: 62
Received Thanks: 5
Quote:
Originally Posted by tolio View Post
ich hab grad mal "https://www.google.de/#q=vb.net+capture+webcam+video" gegooglet, da kommen dutzende sources...
Jup aber wird irgendwo dass Video auch gespeichert?? Ich hab keins gefunden ^^

Quote:
Originally Posted by Frosttall View Post



Die Library die du benötigst:
Danke dass sieht schon mal vielversprechend aus mal gucken ob ich da was vernünftiges Zu Stande bringe

Ok ich hab jetzt erstmal versucht die einzelnen Bilder zu speichern aber noch nicht mal dass geht, anscheinend sieht VB.NET die PictureBox als leer an! Ich kriege auf jeden Fall immer eine Null Reference Exception. Ich hoffe ich habe keinen super simplen Fehler gemacht.

Hier nochmal der neue Source:

Code:
Public Class Form1
    Dim videoHandle As IntPtr
    Dim an As Boolean = False
    Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Declare Auto Function capCreateCaptureWindow Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As Short, ByVal y As Integer, ByVal nWidth As Short, ByVal nHeight As Short, ByVal hWndParent As IntPtr, ByVal nID As Byte) As IntPtr

    Const EM_LINEFROMCHAR As Integer = &HC9
    Const EM_LINEINDEX As Integer = &HBB

    Const WS_CHILD As Integer = &H40000000
    Const WS_VISIBLE As Integer = &H10000000

    Const WM_USER As Short = &H400S
    Const WM_CAP_START As Short = &H400S
    Const WM_CAP_EDIT_COPY As Short = WM_CAP_START + 30
    Const WM_CAP_DRIVER_CONNECT As Short = WM_CAP_START + 10
    Const WM_CAP_SET_PREVIEWRATE As Short = WM_CAP_START + 52
    Const WM_CAP_SET_OVERLAY As Short = WM_CAP_START + 51
    Const WM_CAP_SET_PREVIEW As Short = WM_CAP_START + 50
    Const WM_CAP_DRIVER_DISCONNECT As Short = WM_CAP_START + 11

    Function CreateCaptureWindow(ByRef hWndParent As IntPtr, Optional ByRef x As Short = 0, Optional ByRef y As Short = 0, Optional ByRef nWidth As Short = 640, Optional ByRef nHeight As Short = 420, Optional ByRef nCameraID As Integer = 0) As IntPtr
        Dim previewHandle As IntPtr

        previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, x, y, nWidth, nHeight, hWndParent, 1)
        SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
        SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 30, 0)
        SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
        SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)

        Return previewHandle
    End Function

    Sub Disconnect(ByRef nCaptureHandle As IntPtr, Optional ByRef nCameraID As Integer = 0)
        SendMessage(nCaptureHandle, WM_CAP_DRIVER_DISCONNECT, nCameraID, 0)
    End Sub

    Sub Form2_FormClosing() Handles Me.FormClosing
        Me.Disconnect(videoHandle)
    End Sub

    Sub Button1_Click() Handles Button1.Click
        an = True
        videoHandle = Me.CreateCaptureWindow(PictureBox1.Handle)
        While an = True
            Bild_Speichern()

        End While

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        an = False
        Me.Disconnect(videoHandle)
    End Sub
    Private Sub Bild_Speichern()
        Try
            If (pictureBox1 IsNot Nothing) Then
                Dim BildAlsDateiPfad As String = "C:\User\Desktop\Hallo"
                Dim bm As Bitmap = pictureBox1.Image
                bm.Save(BildAlsDateiPfad & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
            End If
        Catch ex As Exception
            MsgBox("Bild Wurde nicht gespeichert.", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
End Class
Ich hab ja jetzt nicht wirklich viel geändert ^^


Danke für eure Hilfe jetzt schon mal
TheBeanjay is offline  
Old 11/03/2013, 22:41   #11

 
Ravenstorm's Avatar
 
elite*gold: 0
The Black Market: 100/0/0
Join Date: Jan 2010
Posts: 13,150
Received Thanks: 3,206
Kannst du mir sagen was die Funktion genau macht hier:

Code:
videoHandle = Me.CreateCaptureWindow(PictureBox1.Handle)
weil mir scheint als ersetzt du das bild der pictureBox nicht wirklich..
Ravenstorm is offline  
Old 11/04/2013, 15:23   #12
 
'Heaven.'s Avatar
 
elite*gold: 1
The Black Market: 331/0/0
Join Date: Jun 2012
Posts: 5,819
Received Thanks: 3,200



Nutz nen Converter, falls dir C# nicht geläufig ist
'Heaven. is offline  
Old 11/04/2013, 17:45   #13
 
elite*gold: 0
Join Date: Feb 2013
Posts: 62
Received Thanks: 5
Quote:
Originally Posted by Ravenstorm View Post
Kannst du mir sagen was die Funktion genau macht hier:

Code:
videoHandle = Me.CreateCaptureWindow(PictureBox1.Handle)
weil mir scheint als ersetzt du das bild der pictureBox nicht wirklich..
Ich vermute dass es kein Bild ist was in der PictureBox angezeigt wird sondern ein Video Stream oder so :/
TheBeanjay is offline  
Old 11/08/2013, 19:06   #14
 
elite*gold: 0
Join Date: Feb 2013
Posts: 62
Received Thanks: 5
Hat noch jemand Ideen?
TheBeanjay is offline  
Old 11/10/2013, 17:50   #15
 
elite*gold: 0
Join Date: Feb 2013
Posts: 62
Received Thanks: 5
Niemand mehr? Bitte wär schön wenn jemand ne Lösung wüsste
TheBeanjay is offline  
Reply

Tags
problem, visual basic, webcam


Similar Threads Similar Threads
Webcam mit Mikrofon Problem - Das Mikro rauscht heftig!!!
01/12/2012 - Technical Support - 5 Replies
Hallo Leute, ich habe mir vor ein paar tagen eine webcam bei ebay gekauft mit Mikrofon. hier ein bild: http://billiger24.net/images/product_images/popup_ images/240_0.jpg Als ich bei Skype mit einem Freund geredet hab, hat er mich fasst gar nicht verstanden, denn das Mikro hat voll heftig gerauscht. Ich weiß gar nicht wieso und ich denke an meinen Lautsprechern lag es ja überhaupt nicht. Ich habe keine Ahnung wie das passiert ist die cam ist wie neu und hat gestern noch funktioniert. Kann...
Problem mit Webcam
10/01/2011 - Technical Support - 4 Replies
Hallo, ich habe vor einer langen Zeit eine Delux Camera gekauft, nun habe ich fomatiert und Cam geht ned. Deswegen frage ich euch ob ihr mir die Driver iwie auftauchen könnt, oder die Software. Kamera: Webcam Deluxe V865 Danke!
Problem mit integrierter Webcam.
08/15/2011 - Off Topic - 6 Replies
Hey! :) Ich habe einen neuen Laptop seit ca. einem Monat. Folgendes Problem: Seit einigen Tagen funktioniert die Webcam nicht mehr. Info über die Webcam: YouCam von CyberLink. Davor ging die Webcam noch. Nun weiß ich leider nicht, woran es liegt. :/ Kann mir da jemand bitte helfen? (=
Webcam Problem
02/18/2011 - Technical Support - 2 Replies
ohai, wenn ich meine Logitech C200 Webcam in Skype startet, hängt sich der PC komplett auf. Treiber sind von der CD installiert, benutze Win 7. Hoffe mir kann da jemand weiterhelfen. mfg
Webcam Problem
02/01/2011 - Technical Support - 1 Replies
Guten Morgen, Ich habe ein Problem mit meiner Hercules Webcam Deluxe. Ich habe den Treiber aus dem Internet installiert und die Webcam am USB Port angeschlossen nun kommt die Fehlermeldung das ich die Webcam anschliessen soll. Habe alle meine USB Ports ausprobiert jedes mal kommt die gleiche Meldung. Ich wollte mir bald eine neue holen aber bis dahin wollte ich die benutzen wäre nett wenn einer vllt eine Idee hätte.



All times are GMT +1. The time now is 14:56.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.