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.
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.
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:
Public Class CrossHairs
'members
Public xpos As Integer
Public ypos As Integer
Private Sub DrawCrossHairs(ByVal xpos As Integer, ByVal ypos As Integer)
Me.Refresh()
'create the graphics object
Dim grfx As Graphics = PictureBox1.CreateGraphics
'draw the horizontal line
grfx.DrawLine(Pens.Black, 0, ypos, PictureBox1.Width, ypos)
'draw the vertical line
grfx.DrawLine(Pens.Black, xpos, 0, xpos, PictureBox1.Height)
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
'get the x and y co-ords of the cursor
xpos = e.X
ypos = e.Y
DrawCrossHairs(xpos, ypos)
End Sub
End Class
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
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
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...
Re: Display Webcam in PictureBox ?
Thanks for all your suggestions on this, I've now got some idea of how to go about it :)