Capture Images Using Web Camera in ASP.Net 4.5

I was working on a project to develop a web conferencing application. I had no experience in this area but I accepted the project and began working on it.

My first effort was to determine how to integrate the webcam into my application. I searched and found it's very simple. I have been very busy doing this project.

Here is my first and small effort that clarifies my mind toward completion of this project.

You can also do this in the following way.

Requirements

  1. Latest Flash Player
  2. Web Camera

You need to do

The following is what you need to do:

  1. Copy the "WebcamResources" into your new application.
  2. Add the following code to your Default.aspx page:

    <object width="450" height="200"
      param name="movie1" value="WebcamResources/save_picture.swf"
      embed src="WebcamResources/save_picture.swf" width="450" height="200" >
    </object>

    This code will place your Flash object in your web page for capturing the image from the webcam.
     
  3. Create one more page named "ImageConversions.aspx".
  4. Add the following code into the ImageConversion.aspx file for the page load event:

    string str_Photo = Request.Form["image_Data"]; //Get the image from flash file
    byte[] photo = Convert.FromBase64String(str_Photo);
    FileStream f_s = new FileStream("C:\\capture.jpg", FileMode.OpenOrCreate, FileAccess.Write);
    BinaryWriter b_r = new BinaryWriter(f_s);
    b_r.Write(photo);
    b_r.Flush();
    b_r.Close();
    f_s.Close();

The code above will convert the bytes to an image and save the image in the C drive.

Enjoy!

Up Next
    Ebook Download
    View all
    Learn
    View all