Results 1 to 7 of 7

Thread: Display Webcam in PictureBox ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Display Webcam in PictureBox ?

    Is it possible to display the video feed from a webcam in a picturebox ?

    I'm using VB Expess 2005 and have done a fair bit of searching and it seems I'll need to use avicap32.dll but I'm not sure if I can use it to display the
    feed in a picturebox.

    Does anyone know if this will work and if so any good sites that explain the methods available in the dll.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Display Webcam in PictureBox ?

    A PictureBox displays an Image object. It doesn't display animation of any kind unless you count changing the Image at an interval. If you can save your webcam feed as Image objects then you can display it in a PictureBox.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: Display Webcam in PictureBox ?

    So would it be possible to grab a picture say every second and display it ?
    I don't really need realtime video for the application I have in mind but if I could get realtime video it would be a bonus. The other criteria I have is that I must be able to draw lines onto the control as well.

    The idea behind the application is to allow accurate tracking of a telescope during long exposure photography, so I need to be able to draw cross hairs on a guide star to track.

    I've done the cross hair bit, just need to grab the images now, any ideas on how to start this would be greatly appreciated.

    VB Code:
    1. Public Class CrossHairs
    2.     'members
    3.     Public xpos As Integer
    4.     Public ypos As Integer
    5.  
    6.  
    7.     Private Sub DrawCrossHairs(ByVal xpos As Integer, ByVal ypos As Integer)
    8.         Me.Refresh()
    9.         'create the graphics object
    10.         Dim grfx As Graphics = PictureBox1.CreateGraphics
    11.         'draw the horizontal line
    12.         grfx.DrawLine(Pens.Black, 0, ypos, PictureBox1.Width, ypos)
    13.         'draw the vertical line
    14.         grfx.DrawLine(Pens.Black, xpos, 0, xpos, PictureBox1.Height)
    15.     End Sub
    16.  
    17.     Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    18.         'get the x and y co-ords of the cursor
    19.         xpos = e.X
    20.         ypos = e.Y
    21.         DrawCrossHairs(xpos, ypos)
    22.     End Sub
    23. End Class

  4. #4
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Display Webcam in PictureBox ?

    take a look at Windows Media Encoder SDK
    http://msdn.microsoft.com/library/de...automation.asp
    it allows to to do things with the capture stream including previews.
    They have a lot of VB code examples

    Also check out DirectShow

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Display Webcam in PictureBox ?

    Another Idea I had was that you can create a transparent overlay that fits over the top of your video capture window and contains the cursor.

    See this thread for an example in VB6.
    http://www.vbforums.com/showthread.php?t=389720

  6. #6
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Re: Display Webcam in PictureBox ?

    Theres a couple of different ways that I have done it. There is a WIA codebank submission in my sig that shows how to grab snapshots from a webcam, and you can modify it in order to refresh at a certain interval. This might be a little slow, and you won't be able to get quick refreshes (as in 30 frames per second), however if you are talking about grabbing every second or so, it could work.

    Another way to do it is to look for info on avicap32.dll (a dll included with windows, I believe, as my machine had already had it). It lets you stream the video to a control, and refreshes as fast as the camera and system can refresh. The EZVidCap program in my sig is an example of using it. When I was trying to do it, I found a VB6 example and just modified it to work in .NET. You can search around for "webcam avicap32" or something to that matter, here is just one link I found...
    Last edited by gigemboy; Mar 23rd, 2006 at 01:35 AM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: Display Webcam in PictureBox ?

    Thanks for all your suggestions on this, I've now got some idea of how to go about it

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