Results 1 to 3 of 3

Thread: Easy Web Cam Library

  1. #1

    Thread Starter
    Hyperactive Member cptHotkeys's Avatar
    Join Date
    Apr 2007
    Location
    New Zealand
    Posts
    294

    Easy Web Cam Library

    I have attached a zip file which contains a solution with 1 form and a library called WebCamLibrary, for those of you who wish to do some video capture, this is a nice starting point.

    Vampire, sorry I took so long, been busy with study etc...

    I will post some more samples which will show how to encode the images to a format thats a bit more practical for transmission shortly.

    Please post any comments and bugs ect...

    Thanks
    Attached Files Attached Files

    Signatures suck

  2. #2

    Thread Starter
    Hyperactive Member cptHotkeys's Avatar
    Join Date
    Apr 2007
    Location
    New Zealand
    Posts
    294

    Re: Easy Web Cam Library

    Here is a version with "Take Snap Shot" feature, it demonstrates how to set the quality, It is set to save as jpeg, which is the most practical for any situation like this. There is a quality setting which you may change, but I have found that the setting its at in code (25) is ok to use for transmision.

    Here is the code:
    VB2005 Code:
    1. Imports System.Drawing.Imaging
    2. Public Class Form1
    3.  
    4.     Private WC As WebCamLibrary.WebCam
    5.  
    6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.  
    8.         Try
    9.             'Initialize web cam
    10.             WC = WebCamLibrary.WebCam.NewWebCam
    11.         Catch ex As Exception
    12.             'There is a problem, or the user doesnt have a web cam
    13.             MsgBox(ex.Message)
    14.             Application.Exit()
    15.         End Try
    16.  
    17.     End Sub
    18.  
    19.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    20.  
    21.         'Set background image to a frame from the camera.
    22.         Me.BackgroundImage = Image.FromStream(New IO.MemoryStream(WC.GrabFrame))
    23.  
    24.     End Sub
    25.  
    26.     Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    27.  
    28.         'Set the interval to 100, which is 10 frames per second
    29.         Timer1.Interval = 1
    30.         Timer1.Start()
    31.  
    32.     End Sub
    33.  
    34.     Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
    35.  
    36.         'Stop the timer
    37.         Timer1.Stop()
    38.  
    39.     End Sub
    40.  
    41.     Private Sub btnSnapShot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSnapShot.Click
    42.  
    43.         Dim myBitmap As Bitmap
    44.         Dim myImageCodecInfo As ImageCodecInfo
    45.         Dim myEncoder As Encoder
    46.         Dim myEncoderParameter As EncoderParameter
    47.         Dim myEncoderParameters As EncoderParameters
    48.  
    49.         ' Create an image from the web cam.
    50.         myBitmap = New Bitmap(Image.FromStream(New IO.MemoryStream(WC.GrabFrame)))
    51.  
    52.         ' Get an ImageCodecInfo object that represents the JPEG codec.
    53.         myImageCodecInfo = GetEncoderInfo("image/jpeg")
    54.  
    55.         ' Create an Encoder object based on the GUID
    56.         ' for the Quality parameter category.
    57.         myEncoder = Encoder.Quality
    58.  
    59.         ' Create an EncoderParameters object.
    60.         ' An EncoderParameters object has an array of EncoderParameter
    61.         ' objects. In this case, there is only one
    62.         ' EncoderParameter object in the array.
    63.         myEncoderParameters = New EncoderParameters(1)
    64.  
    65.         ' Save the bitmap as a JPEG file with quality level 25. (you may set the quality between 0 - 100)
    66.         myEncoderParameter = New EncoderParameter(myEncoder, 25)
    67.         myEncoderParameters.Param(0) = myEncoderParameter
    68.         myBitmap.Save("theJpeg.jpg", myImageCodecInfo, myEncoderParameters)
    69.  
    70.     End Sub
    71.  
    72.     Private Shared Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
    73.  
    74.         Dim i As Integer
    75.         Dim encoders() As ImageCodecInfo
    76.         'Get all image encoders
    77.         encoders = ImageCodecInfo.GetImageEncoders()
    78.  
    79.         'loop through encoders and return the matching encoder
    80.         i = 0
    81.         While i < encoders.Length
    82.             If encoders(i).MimeType = mimeType Then
    83.                 Return encoders(i)
    84.             End If
    85.             i += 1
    86.         End While
    87.         Return Nothing
    88.  
    89.     End Function
    90.  
    91. End Class
    Please post comments or bugs...
    Attached Files Attached Files
    Last edited by cptHotkeys; Sep 13th, 2007 at 11:01 PM.

    Signatures suck

  3. #3
    Addicted Member
    Join Date
    Jul 2007
    Posts
    159

    Re: Easy Web Cam Library

    Thanks - will try it out soon!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width