Click here to Skip to main content
14,689,231 members
Articles » Web Development » Charts, Graphs and Images » Images and multimedia
Tip/Trick
Posted 16 Jan 2013

Tagged as

Stats

196.9K views
10.8K downloads
20 bookmarked

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
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. <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. 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)

Share

About the Author

nehas1jan
Software Developer (Junior) TIV Labs
India India
No Biography provided

Comments and Discussions

 
GeneralRe: please advise Pin
nehas1jan26-May-13 7:06
Membernehas1jan26-May-13 7:06 
GeneralRe: please advise Pin
mshma26-May-13 7:10
Membermshma26-May-13 7:10 
GeneralRe: please advise Pin
nehas1jan26-May-13 7:16
Membernehas1jan26-May-13 7:16 
GeneralRe: please advise Pin
Ivanov Correa8-Dec-13 16:19
MemberIvanov Correa8-Dec-13 16:19 
GeneralRe: please advise Pin
nehas1jan8-Dec-13 18:47
Membernehas1jan8-Dec-13 18:47 
Questionthis webcam window is about 200x100 px what to do if i want to see web cam in 500x500px area Pin
mahaveer singh ratnoo15-Mar-13 12:31
Membermahaveer singh ratnoo15-Mar-13 12:31 
AnswerRe: this webcam window is about 200x100 px what to do if i want to see web cam in 500x500px area Pin
Pa.hor14-Apr-13 3:00
MemberPa.hor14-Apr-13 3:00 
GeneralRe: this webcam window is about 200x100 px what to do if i want to see web cam in 500x500px area Pin
Ivanov Correa15-Dec-13 21:02
MemberIvanov Correa15-Dec-13 21:02 
Questionstreaming? Pin
piling26-Feb-13 6:44
Memberpiling26-Feb-13 6:44 
AnswerRe: streaming? Pin
nehas1jan26-Feb-13 19:35
Membernehas1jan26-Feb-13 19:35 
GeneralRe: streaming? Pin
piling27-Feb-13 0:03
Memberpiling27-Feb-13 0:03 
QuestionPls. Help me Pin
Yamuna Prasad Singh19-Feb-13 21:13
MemberYamuna Prasad Singh19-Feb-13 21:13 
AnswerRe: Pls. Help me Pin
nehas1jan19-Feb-13 21:17
Membernehas1jan19-Feb-13 21:17 
GeneralRe: Pls. Help me Pin
Yamuna Prasad Singh19-Feb-13 21:56
MemberYamuna Prasad Singh19-Feb-13 21:56 
GeneralRe: Pls. Help me Pin
nehas1jan19-Feb-13 22:08
Membernehas1jan19-Feb-13 22:08 
GeneralMy vote of 4 Pin
Shubh Agrahari18-Jan-13 2:53
MemberShubh Agrahari18-Jan-13 2:53 
GeneralRe: My vote of 4 Pin
nehas1jan18-Jan-13 2:55
Membernehas1jan18-Jan-13 2:55 
GeneralRe: My vote of 4 Pin
Shubh Agrahari18-Jan-13 2:58
MemberShubh Agrahari18-Jan-13 2:58 
GeneralRe: My vote of 4 Pin
nehas1jan18-Jan-13 2:59
Membernehas1jan18-Jan-13 2:59 
GeneralRe: My vote of 4 Pin
Shubh Agrahari18-Jan-13 3:10
MemberShubh Agrahari18-Jan-13 3:10 
GeneralRe: My vote of 4 Pin
nehas1jan18-Jan-13 3:19
Membernehas1jan18-Jan-13 3:19 

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.