Hi All,
I need help once again, I have tried searching all day with no luck.
Im making a camera/video capture app for my shinny new windows tablet (win 7 ultimate). I have tried a few apps but all are really crap and not what im after.
From searching I found the avicap32.dll method which on my dev computer works perfect, on my tablet however it doesnt.
The reason for this is the tablet has 2 webcams, front and back, both use the very same driver so show as 1 source on the tablet. when i select the source it gives me the option of picking abc usb cam or cba usb cam but still doesnt work.
I have no idea how to get around this :(
also skype can list the name of the webcams and display perfectly as can the trialed apps.
Please see below code
so basically the listbox on the form fills with driver details, i would then select it and the preview would appear in the picture box, on the tablet this doesnt happen, both webcams are listed under same driver, select it and windows asks which camera but never loads the preview (ideally i would like that windows pop up to not show as well i have the camera names if that helps).
I did look into some other options like directshow.net and even webcamlib.dll (which looks simple but cant even load the dll).
EDIT**** I added a msgbox to the area that errors on connecting and it ran so it seems like a connection error, seeing as it connects using driver and both have same driver it must not know which one to use. stil any help appriciated**
any and all help is appriciated, i thought this would be easy and is was, until 2 webcams came into it :(
I need help once again, I have tried searching all day with no luck.
Im making a camera/video capture app for my shinny new windows tablet (win 7 ultimate). I have tried a few apps but all are really crap and not what im after.
From searching I found the avicap32.dll method which on my dev computer works perfect, on my tablet however it doesnt.
The reason for this is the tablet has 2 webcams, front and back, both use the very same driver so show as 1 source on the tablet. when i select the source it gives me the option of picking abc usb cam or cba usb cam but still doesnt work.
I have no idea how to get around this :(
also skype can list the name of the webcams and display perfectly as can the trialed apps.
Please see below code
Code:
Const WM_CAP_START = &H400S
Const WS_CHILD = &H40000000
Const WS_VISIBLE = &H10000000
Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
Const WM_CAP_EDIT_COPY = WM_CAP_START + 30
Const WM_CAP_SEQUENCE = WM_CAP_START + 62
Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Const SWP_NOMOVE = &H2S
Const SWP_NOSIZE = 1
Const SWP_NOZORDER = &H4S
Const HWND_BOTTOM = 1
'--The capGetDriverDescription function retrieves the version
' description of the capture driver--
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _
(ByVal wDriverIndex As Short, _
ByVal lpszName As String, ByVal cbName As Integer, _
ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean
'--The capCreateCaptureWindow function creates a capture window--
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 hWnd As Integer, _
ByVal nID As Integer) As Integer
'--This function sends the specified message to a window or windows--
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal Msg As Integer, _
ByVal wParam As Integer, _
<MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer
'--Sets the position of the window relative to the screen buffer--
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
(ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, _
ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer) As Integer
'--This function destroys the specified window--
Declare Function DestroyWindow Lib "user32" _
(ByVal hndw As Integer) As Boolean
'---used to identify the video source---
Dim VideoSource As Integer
'---used as a window handle---
Dim hWnd As Integer
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
Dim path As String
path = "C:\data\"
Dim number As Integer
number = System.IO.Directory.GetFiles(path).Length
SendMessage(hWnd, WM_CAP_EDIT_COPY, 0, 0)
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(path & "image" & number & ".jpg", Imaging.ImageFormat.Jpeg)
PictureBox2.Image = Image.FromFile(path & "image" & number & ".jpg")
PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
End Using
End If
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
System.IO.Directory.CreateDirectory("C:\data")
ListVideoSources()
End Sub
'---list all the various video sources---
Private Sub ListVideoSources()
Dim DriverName As String = Space(80)
Dim DriverVersion As String = Space(80)
For i As Integer = 0 To 9
If capGetDriverDescriptionA(i, DriverName, 80, _
DriverVersion, 80) Then
lstVideoSources.Items.Add(DriverName.Trim)
End If
Next
End Sub
'---list all the video sources---
Private Sub lstVideoSources_SelectedIndexChanged( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles lstVideoSources.SelectedIndexChanged
'---check which video source is selected---
VideoSource = lstVideoSources.SelectedIndex
'---preview the selected video source
PreviewVideo(picCapture)
End Sub
'---preview the selected video source---
Private Sub PreviewVideo(ByVal pbCtrl As PictureBox)
hWnd = capCreateCaptureWindowA(VideoSource, _
WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
0, pbCtrl.Handle.ToInt32, 0)
If SendMessage( _
hWnd, WM_CAP_DRIVER_CONNECT, _
VideoSource, 0) Then
'---set the preview scale---
SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
'---set the preview rate (ms)---
SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
'---start previewing the image---
SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
'---resize window to fit in PictureBox control---
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, _
pbCtrl.Width, pbCtrl.Height, _
SWP_NOMOVE Or SWP_NOZORDER)
Else
'--error connecting to video source---
DestroyWindow(hWnd)
End If
End Sub
'---stop the preview window---
Private Sub btnStopCamera_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs)
StopPreviewWindow()
End Sub
'--disconnect from video source---
Private Sub StopPreviewWindow()
SendMessage(hWnd, WM_CAP_DRIVER_DISCONNECT, VideoSource, 0)
DestroyWindow(hWnd)
End Sub
'---Start recording the video---
Private Sub btnStartRecording_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnStartRecording.Click
btnStartRecording.Enabled = False
btnStopRecording.Enabled = True
'---start recording---
SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0)
End Sub
'---stop recording and save it on file---
Private Sub btnStopRecording_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnStopRecording.Click
btnStartRecording.Enabled = True
btnStopRecording.Enabled = False
'---save the recording to file---
SendMessage(hWnd, WM_CAP_FILE_SAVEAS, 0, _
"C:\RecordedVideo.avi")
End Sub
I did look into some other options like directshow.net and even webcamlib.dll (which looks simple but cant even load the dll).
EDIT**** I added a msgbox to the area that errors on connecting and it ran so it seems like a connection error, seeing as it connects using driver and both have same driver it must not know which one to use. stil any help appriciated**
any and all help is appriciated, i thought this would be easy and is was, until 2 webcams came into it :(