I'm trying to create a vb.net app that will run on a tablet and allow it to use the camera, capture an image and display it in a picture box?
Has anyone done anything similar
When I searched the web for "vb.net web cam image capture" I found a number of seemingly relevant results. Did you do the same? If not, why not? If so, what do you not understand about what you found? You should try to make use of existing information first, rather than ask people to repeat what's already out there. If you can't find what you need or can't get what you find to work, then you would post to a forum with a more specific question.
I searched and tried extensively before posting, I could not get it to work on the windows 8 and 10 tablets I have with me.
Some code I found and used worked on pc but showed a blank screen and did not capture on the tablet.
My requirement is to create an app that runs without deployemnt through the windows store
If you have code that you think should work but doesn't then show us that and tell us what actually happens. If you tell us nothing then we're likely to waste our time and yours giving you information that you already have and it could be that the code you have is perfect but for one small detail. Just give us ALL the relevant information.
On my laptop once capture is clicked it will show what will be captured on pressing save it saves the file fine.
On the windows 8 tablet pressing capture shows a black picture box.
On Windows 10 tablet it asks for front or rear camera capture but both option lead to the same result a black picture box
Imports System
Public Class Form1
'Load Webcam Device List
Private Sub LoadDeviceList()
On Error Resume Next
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Integer = 0
Do
bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
If bReturn Then lst1.Items.Add(strName.Trim)
x += 1
Application.DoEvents()
Loop Until bReturn = False
End Sub
'Open View
Private Sub OpenPreviewWindow()
On Error Resume Next
Dim iHeight As Integer = pview.Height
Dim iWidth As Integer = pview.Width
'
' Open Preview window in picturebox
'
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
480, pview.Handle.ToInt32, 0)
'
' Connect to device
'
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
'
'Set the preview scale
'
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
'
'Set the preview rate in milliseconds
'
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
'
'Start previewing the image from the camera
'
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
'
' Resize window to fit in picturebox
'
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, pview.Width, pview.Height, _
SWP_NOMOVE Or SWP_NOZORDER)
cmd1.Enabled = False
cmd2.Enabled = True
cmd3.Enabled = True
Else
'
' Error connecting to device close window
'
DestroyWindow(hHwnd)
cmd1.Enabled = True
cmd2.Enabled = False
cmd3.Enabled = False
pview.Image = Nothing
pview.SizeMode = PictureBoxSizeMode.StretchImage
pview.BackColor = Color.Black
pview.BackgroundImage = Nothing
pview.BackgroundImageLayout = ImageLayout.None
pview.Refresh()
End If
End Sub
Private Sub ClosePreviewWindow()
On Error Resume Next
'
' Disconnect from device
'
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)
'
' close window
'
DestroyWindow(hHwnd)
cmd1.Enabled = True
cmd2.Enabled = False
cmd3.Enabled = False
pView.Image = Nothing
pview.SizeMode = PictureBoxSizeMode.StretchImage
pview.BackColor = Color.Black
pview.BackgroundImage = Nothing
pview.BackgroundImageLayout = ImageLayout.None
pview.Refresh()
End Sub
'If Form Closed
Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
On Error Resume Next
'If Played the Stopped
If cmd2.Enabled Then
ClosePreviewWindow()
End If
End Sub
'Set Object To Default Value
Private Sub ClearAllObject()
On Error Resume Next
'opt1.Checked = False
'opt2.Checked = True
lst1.Items.Clear()
lst1.Refresh()
pView.BackColor = Color.Black
pView.BackgroundImageLayout = ImageLayout.Stretch
pView.Image = Nothing
pView.SizeMode = PictureBoxSizeMode.StretchImage
pView.Refresh()
cmd1.Enabled = True
cmd2.Enabled = False
cmd3.Enabled = False
'Load Device List
Call LoadDeviceList()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
On Error Resume Next
'Load Object Value TO Default
ClearAllObject()
End Sub
Private Sub cmd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd1.Click
On Error Resume Next
'Device
iDevice = lst1.SelectedIndex
'Load And Capture Device
OpenPreviewWindow()
End Sub
Private Sub cmd2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd2.Click
On Error Resume Next
'Stop Device Capture
ClosePreviewWindow()
End Sub
Private Sub cmd3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd3.Click
On Error Resume Next
Dim data As IDataObject
Dim bmap As Image
Dim imgpath As String = ""
'
' Copy image to clipboard
'
SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
'
' Get image from clipboard and convert it to a bitmap
'
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
pView.Image = bmap
'Stop Device Capture
ClosePreviewWindow()
'Set Button
cmd3.Enabled = False
cmd2.Enabled = False
cmd1.Enabled = True
'Set Save Dialog
sfdImages.FileName = ""
sfdImages.Title = "Save Picture"
sfdImages.Filter = "Bitmap|*.bmp|Jpeg|*.jpg|GIF|*.gif|PNG|*.png"
'If File Name Not Equal "" then Save The File
If sfdImages.ShowDialog = DialogResult.OK Then
imgpath = sfdImages.FileName
Select Case Microsoft.VisualBasic.Right$(sfdImages.FileName, 3)
Case Is = "bmp"
bmap.Save(sfdImages.FileName, Imaging.ImageFormat.Bmp)
Case Is = "jpg"
bmap.Save(sfdImages.FileName, Imaging.ImageFormat.Jpeg)
Case Is = "gif"
bmap.Save(sfdImages.FileName, Imaging.ImageFormat.Gif)
Case Is = "png"
bmap.Save(sfdImages.FileName, Imaging.ImageFormat.Png)
End Select
End If
End If
data = Nothing
pView.Image = Image.FromFile(imgpath) 'imgpath
End Sub
End Class
I have identical problems with similar code, using avicap32.dll to list the cameras.
Oddly I found that connecting a separate webcam via USB seems to work, but the internal cameras fail at the connection procedure, even if you delay the connection attempt by a short while. I'm wandering if this is related to a failing in that dll file, possibly due to it's age and if there is an alternative solution in .NET that will allow me to capture stills from integrated cameras.
Windows, Unity, etc seem to pick up the cameras without issue and play video through it without issue. Perhaps an alternative method is viable from within VB.NET? I'd be interested to hear of any solutions to this.
Yeah, it's definitely an issue with avicap32.dll being an old link library, using DirectShow instead makes it all work properly. Tested this out on a few tablet PCs including the LINX12x64 ,Fusion 5 and it's way more reliable, like 100% reliable. Don't use avicap32.dll if you can avoid it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.