You can use the Touchless library. Found here:
http://touchless.codeplex.com/[
^] With this Class:
Imports System.Net.Sockets
Imports System.Threading
Imports TouchlessLib
Public Class Form1
Dim subscriber As New UdpClient()
Dim publisher As New UdpClient()
Dim mycomputername As String = Environment.MachineName
Dim mycomputerIP() As System.Net.IPAddress = System.Net.Dns.GetHostAddresses(mycomputername)
Dim Touchless As New TouchlessLib.TouchlessMgr
Dim Camera1 As TouchlessLib.Camera = Touchless.Cameras.ElementAt(0)
Dim picsize As Size = New Size(160, 120)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
publisher.Client.Blocking = False
subscriber.Client.ReceiveTimeout = 100
subscriber.Client.Blocking = False
subscriber.ExclusiveAddressUse = False
publisher.ExclusiveAddressUse = False
TB_Host.Text = Environment.MachineName
Label3.Text = "My Name: " & Environment.MachineName
Touchless.CurrentCamera = Camera1
Touchless.CurrentCamera.CaptureWidth = picsize.Width
Touchless.CurrentCamera.CaptureHeight = picsize.Height
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
Dim bitmapz As Bitmap = New Bitmap(picsize.Width, picsize.Height)
bitmapz = Touchless.CurrentCamera.GetCurrentImage
PictureBox1.Image = bitmapz
Dim sendbytes() As Byte
bytesfromimage(sendbytes, bitmapz)
publisher.Send(sendbytes, sendbytes.Length)
Catch ex As Exception
End Try
Try
Dim ep As System.Net.IPEndPoint = New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
Dim rcvbytes() As Byte = subscriber.Receive(ep)
Dim bitmapz As Bitmap = New Bitmap(picsize.Width, picsize.Height)
imagefrombytes(rcvbytes, bitmapz)
PictureBox2.Image = bitmapz
Catch ex As Exception
End Try
End Sub
Private Sub imagefrombytes(ByRef bytez() As Byte, ByRef piccolor As Bitmap)
Dim rect As New Rectangle(0, 0, piccolor.Width, piccolor.Height)
Dim bmpData As System.Drawing.Imaging.BitmapData = piccolor.LockBits(rect, _
Drawing.Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppRgb)
Dim ptr As IntPtr = bmpData.Scan0
Dim bytes As Integer = bmpData.Stride * piccolor.Height
Dim rgbValues(bytes - 1) As Byte
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)
Dim secondcounter As Integer
Dim tempred As Integer
Dim tempblue As Integer
Dim tempgreen As Integer
Dim tempalpha As Integer
secondcounter = 0
While secondcounter < rgbValues.Length
tempblue = rgbValues(secondcounter)
tempgreen = rgbValues(secondcounter + 1)
tempred = rgbValues(secondcounter + 2)
tempalpha = rgbValues(secondcounter + 3)
tempalpha = 255
tempred = bytez(((secondcounter * 0.25) * 3) + 0)
tempgreen = bytez(((secondcounter * 0.25) * 3) + 1)
tempblue = bytez(((secondcounter * 0.25) * 3) + 2)
rgbValues(secondcounter) = tempblue
rgbValues(secondcounter + 1) = tempgreen
rgbValues(secondcounter + 2) = tempred
rgbValues(secondcounter + 3) = tempalpha
secondcounter = secondcounter + 4
End While
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes)
piccolor.UnlockBits(bmpData)
End Sub
Private Sub bytesfromimage(ByRef bytez() As Byte, ByRef piccolor As Bitmap)
Dim rect As New Rectangle(0, 0, piccolor.Width, piccolor.Height)
Dim bmpData As System.Drawing.Imaging.BitmapData = piccolor.LockBits(rect, _
Drawing.Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppRgb)
Dim ptr As IntPtr = bmpData.Scan0
Dim bytes As Integer = bmpData.Stride * piccolor.Height
Dim rgbValues(bytes - 1) As Byte
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)
Dim secondcounter As Integer
Dim tempred As Integer
Dim tempblue As Integer
Dim tempgreen As Integer
Dim tempalpha As Integer
secondcounter = 0
Dim bytelist As List(Of Byte) = New List(Of Byte)
While secondcounter < rgbValues.Length
tempblue = rgbValues(secondcounter)
tempgreen = rgbValues(secondcounter + 1)
tempred = rgbValues(secondcounter + 2)
tempalpha = rgbValues(secondcounter + 3)
tempalpha = 255
bytelist.Add(tempred)
bytelist.Add(tempgreen)
bytelist.Add(tempblue)
rgbValues(secondcounter) = tempblue
rgbValues(secondcounter + 1) = tempgreen
rgbValues(secondcounter + 2) = tempred
rgbValues(secondcounter + 3) = tempalpha
secondcounter = secondcounter + 4
End While
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes)
piccolor.UnlockBits(bmpData)
Dim bytearray(bytelist.Count - 1) As Byte
For i = 0 To bytelist.Count - 1
bytearray(i) = bytelist(i)
Next
bytez = bytearray
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
publisher.Connect(TB_Host.Text, 2013)
subscriber.Client.Bind(New Net.IPEndPoint(Net.IPAddress.Any, 2013))
End Sub
End Class
Just to note: This will stream the webcam, but with effortless modification, you can take snaps too. You can see how to adapt it to your desires by studying the Touchless Library. ;)