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:
    1. <object width="450" height="200"  
    2.   param name="movie1" value="WebcamResources/save_picture.swf"  
    3.   embed src="WebcamResources/save_picture.swf" width="450" height="200" >  
    4. </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:
    1. string str_Photo = Request.Form["image_Data"]; //Get the image from flash file  
    2. byte[] photo = Convert.FromBase64String(str_Photo);  
    3. FileStream f_s = new FileStream("C:\\capture.jpg", FileMode.OpenOrCreate, FileAccess.Write);  
    4. BinaryWriter b_r = new BinaryWriter(f_s);  
    5. b_r.Write(photo);  
    6. b_r.Flush();  
    7. b_r.Close();  
    8. f_s.Close();  

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

Enjoy!


Similar Articles