Click here to Skip to main content
15,881,803 members
Articles / Web Development / ASP.NET
Tip/Trick

Capture images using web camera in ASP.NET 4.5

Rate me:
Please Sign up or sign in to vote.
4.66/5 (16 votes)
16 Jan 2013CPOL 243.4K   11.1K   20   71
How to capture images using web camera in ASP.NET 4.5.

Introduction

I was working for a project to develop a web conferencing application. I accepted the project and started to work on it. My first effort was to integrate a web cam into my application. I searched about it and found that it’s very simple. I have been very busy doing this project. Here is my first and small effort which makes my mind clear about the completion of this project.

Requirements

  1. Latest Flash player
  2. Web camera

The solution

You need to:

  1. Copy the “WebcamResources” into your new application.
  2. Add the following code in to your Default.aspx page:
  3. XML
    <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 into your web page, used to capture the images from the web cam.

  4. Add one more page there with the name ImageConversions.aspx.
  5. Add the following code into ImageConversion.aspx at the page load event:
  6. C#
    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 above code will convert the bytes to an image and will save the image in the c drive.

Enjoy!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Junior) TIV Labs
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionstring returned from Request.Form["image_Data"] is null Pin
Member 146136347-Oct-19 6:38
Member 146136347-Oct-19 6:38 
QuestionWebcam Resources Pin
Member 140476459-Nov-18 20:54
Member 140476459-Nov-18 20:54 
Questionwebcam problem Pin
Member 1395733421-Aug-18 21:55
Member 1395733421-Aug-18 21:55 
QuestionImageConversions Pin
sandeep reddy palannagari15-Mar-18 1:02
sandeep reddy palannagari15-Mar-18 1:02 
QuestionImage Size Pin
HarryMadaan10-Oct-17 19:13
HarryMadaan10-Oct-17 19:13 
QuestionImage not saving Pin
Member 1047604027-Apr-17 20:45
Member 1047604027-Apr-17 20:45 
AnswerRe: Image not saving Pin
HarryMadaan10-Oct-17 0:02
HarryMadaan10-Oct-17 0:02 
AnswerRe: Image not saving Pin
HarryMadaan10-Oct-17 19:11
HarryMadaan10-Oct-17 19:11 
QuestionRequest is not available in this context Pin
Member _SunilMishra12-Jul-16 2:14
professionalMember _SunilMishra12-Jul-16 2:14 
Question" string str_Photo = Request.Form["image_Data"] " returns null Pin
Member 1163313422-Apr-15 19:03
Member 1163313422-Apr-15 19:03 
AnswerRe: " string str_Photo = Request.Form["image_Data"] " returns null Pin
HarryMadaan10-Oct-17 0:02
HarryMadaan10-Oct-17 0:02 
Questioncode not working . Pin
Member 1095387415-Jan-15 4:30
Member 1095387415-Jan-15 4:30 
Questionhow to capture image from webcam without showing User in asp.net c# Pin
aminch3276-Jan-15 22:51
aminch3276-Jan-15 22:51 
AnswerRe: how to capture image from webcam without showing User in asp.net c# Pin
Member 1143216629-Aug-16 2:19
Member 1143216629-Aug-16 2:19 
QuestionImage not save in folder (online) Pin
Prasanna Mhamane14-Nov-14 1:12
Prasanna Mhamane14-Nov-14 1:12 
AnswerRe: Image not save in folder (online) Pin
nehas1jan14-Nov-14 1:14
nehas1jan14-Nov-14 1:14 
QuestionNeed to change filename by taking name from another page Pin
GauravSotani2713-Nov-14 1:12
GauravSotani2713-Nov-14 1:12 
AnswerRe: Need to change filename by taking name from another page Pin
nehas1jan14-Nov-14 1:16
nehas1jan14-Nov-14 1:16 
GeneralRe: Need to change filename by taking name from another page Pin
GauravSotani2714-Nov-14 1:37
GauravSotani2714-Nov-14 1:37 
AnswerRe: Need to change filename by taking name from another page Pin
GauravSotani2714-Nov-14 1:36
GauravSotani2714-Nov-14 1:36 
QuestionImage not save in folder (online) Pin
Reshma Khaire11-Nov-14 0:37
professionalReshma Khaire11-Nov-14 0:37 
AnswerRe: Image not save in folder (online) Pin
nehas1jan11-Nov-14 0:42
nehas1jan11-Nov-14 0:42 
GeneralRe: Image not save in folder (online) Pin
Member 1122623611-Nov-14 18:11
Member 1122623611-Nov-14 18:11 
GeneralRe: Image not save in folder (online) Pin
nehas1jan14-Nov-14 1:17
nehas1jan14-Nov-14 1:17 
GeneralRe: Image not save in folder (online) Pin
Member 1095387415-Jan-15 4:32
Member 1095387415-Jan-15 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.