Home > Uncategorized > Capturing a webcam to an AVI file

Capturing a webcam to an AVI file

I previously wrote an application which captures a webcam in VB.NET (http://www.webtropy.com/articles/art7.asp) However, this only shows a webcam, and has no facilities to record. Therefore, I added a new function to save bitmaps
 

Public Sub SaveBitmap(ByVal filename As String)

SendMessage(lwndC, WM_CAP_FILE_SAVEDIB, 0&, filename)

End Sub

 

Where WM_CAP_FILE_SAVEDIB is defined as WM_USER+25

– It also requires an overloaded SendMessage declaration, which accepts a string as it’s final parameter.

 

I then found some CS code which converts BMP files to AVI (http://midget3d.com/gabe/AviLib.zip)

 

then used this to write bitmaps to disk, and build them into an AVI

 

saveFileDialog.Filter="*.avi|*.avi";

saveFileDialog.ShowDialog();

string strAVI = saveFileDialog.FileName;

string strBMP = saveFileDialog.FileName.Replace(".avi",".bmp");

AviWriter aviWriter =

new AviWriter(strAVI, AviCompression.None, 24, 320, 240);

isRecording =

true;

while(isRecording)

{

webcamControl1.SaveBitmap(strBMP);

aviWriter.WriteFrame(

new Bitmap(strBMP));

Application.DoEvents();

}

aviWriter.Close();

 
 
 
Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: