Click here to Skip to main content
11,718,589 members (86,934 online)
Click here to Skip to main content

Capture images using web camera in ASP.NET 4.5

, 16 Jan 2013 CPOL 53.3K 5.9K 18
Rate this:
Please Sign up or sign in to vote.
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

You may also be interested in...

Comments and Discussions

 
Question" string str_Photo = Request.Form["image_Data"] " returns null Pin
Member 1163313422-Apr-15 19:03
memberMember 1163313422-Apr-15 19:03 
Questioncode not working . Pin
Member 1095387415-Jan-15 4:30
memberMember 1095387415-Jan-15 4:30 
Questionhow to capture image from webcam without showing User in asp.net c# Pin
aminch3276-Jan-15 22:51
memberaminch3276-Jan-15 22:51 
QuestionImage not save in folder (online) Pin
Prasanna Mhamane14-Nov-14 1:12
memberPrasanna Mhamane14-Nov-14 1:12 
AnswerRe: Image not save in folder (online) Pin
nehas1jan14-Nov-14 1:14
membernehas1jan14-Nov-14 1:14 
QuestionNeed to change filename by taking name from another page Pin
Member 880009713-Nov-14 1:12
memberMember 880009713-Nov-14 1:12 
AnswerRe: Need to change filename by taking name from another page Pin
nehas1jan14-Nov-14 1:16
membernehas1jan14-Nov-14 1:16 
GeneralRe: Need to change filename by taking name from another page Pin
GauravSotani2714-Nov-14 1:37
memberGauravSotani2714-Nov-14 1:37 
AnswerRe: Need to change filename by taking name from another page Pin
GauravSotani2714-Nov-14 1:36
memberGauravSotani2714-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
membernehas1jan11-Nov-14 0:42 
GeneralRe: Image not save in folder (online) Pin
Member 1122623611-Nov-14 18:11
memberMember 1122623611-Nov-14 18:11 
GeneralRe: Image not save in folder (online) Pin
nehas1jan14-Nov-14 1:17
membernehas1jan14-Nov-14 1:17 
GeneralRe: Image not save in folder (online) Pin
Member 1095387415-Jan-15 4:32
memberMember 1095387415-Jan-15 4:32 
GeneralWebCam Device Pin
tejasGhadge11-Oct-14 5:51
membertejasGhadge11-Oct-14 5:51 
Questionhere is good example using Jquery plugin for Asp.net Pin
saineshwar15-Apr-14 18:13
membersaineshwar15-Apr-14 18:13 
QuestionCan we use different file name , instead of ImageConversion.aspx ? Pin
nayeemkhan2427-Feb-14 20:47
membernayeemkhan2427-Feb-14 20:47 
AnswerRe: Can we use different file name , instead of ImageConversion.aspx ? Pin
Imran_hus6-Jun-14 20:39
memberImran_hus6-Jun-14 20:39 
Questionimage size Pin
agnushallard18-Feb-14 2:54
memberagnushallard18-Feb-14 2:54 
Questionnot getting the file in desired path or in any path please give us where is it going wrong Pin
viral198620-Jan-14 19:20
memberviral198620-Jan-14 19:20 
AnswerRe: not getting the file in desired path or in any path please give us where is it going wrong Pin
nehas1jan20-Jan-14 19:23
membernehas1jan20-Jan-14 19:23 
QuestionImage is not saving in C drive... Pin
Member 1019895822-Dec-13 19:18
memberMember 1019895822-Dec-13 19:18 
QuestionCan I avoid the "Permissions window"? Pin
Ivanov Correa15-Dec-13 20:24
memberIvanov Correa15-Dec-13 20:24 
AnswerRe: Can I avoid the "Permissions window"? Pin
Ivanov Correa15-Dec-13 20:48
memberIvanov Correa15-Dec-13 20:48 
QuestionThanks! - Worked "out of the box" Pin
Ivanov Correa8-Dec-13 15:16
memberIvanov Correa8-Dec-13 15:16 
Questionscanner and tab device for signature Pin
Faisal suleman18-Nov-13 20:37
memberFaisal suleman18-Nov-13 20:37 
QuestionWebCam Pin
Muhammad Kashif Saleem23-Aug-13 19:17
memberMuhammad Kashif Saleem23-Aug-13 19:17 
AnswerRe: WebCam Pin
LogicPlayer28-Apr-14 21:01
memberLogicPlayer28-Apr-14 21:01 
Questionwant to add image in server side Pin
dilfizo29-Jul-13 3:16
memberdilfizo29-Jul-13 3:16 
AnswerRe: want to add image in server side Pin
nehas1jan30-Jul-13 2:03
membernehas1jan30-Jul-13 2:03 
QuestionError encountered Pin
smartbill12327-Jul-13 12:45
membersmartbill12327-Jul-13 12:45 
QuestionRegarding the installation files Pin
gayaj26-Jul-13 7:13
membergayaj26-Jul-13 7:13 
Questionplease advise Pin
mshma25-May-13 3:25
membermshma25-May-13 3:25 
AnswerRe: please advise Pin
nehas1jan25-May-13 7:19
membernehas1jan25-May-13 7:19 
GeneralRe: please advise Pin
mshma26-May-13 4:50
membermshma26-May-13 4:50 
GeneralRe: please advise Pin
nehas1jan26-May-13 5:11
membernehas1jan26-May-13 5:11 
GeneralRe: please advise Pin
mshma26-May-13 5:48
membermshma26-May-13 5:48 
GeneralRe: please advise Pin
nehas1jan26-May-13 5:49
membernehas1jan26-May-13 5:49 
GeneralRe: please advise Pin
mshma26-May-13 6:05
membermshma26-May-13 6:05 
GeneralRe: please advise Pin
nehas1jan26-May-13 6:06
membernehas1jan26-May-13 6:06 
GeneralRe: please advise Pin
mshma26-May-13 6:10
membermshma26-May-13 6:10 
GeneralRe: please advise Pin
nehas1jan26-May-13 6:16
membernehas1jan26-May-13 6:16 
GeneralRe: please advise Pin
Ivanov Correa8-Dec-13 15:19
memberIvanov Correa8-Dec-13 15:19 
GeneralRe: please advise Pin
nehas1jan8-Dec-13 17:47
membernehas1jan8-Dec-13 17: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 11:31
membermahaveer singh ratnoo15-Mar-13 11: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 2:00
memberPa.hor14-Apr-13 2: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 20:02
memberIvanov Correa15-Dec-13 20:02 
Questionstreaming? Pin
dogancanbakir26-Feb-13 5:44
memberdogancanbakir26-Feb-13 5:44 
AnswerRe: streaming? Pin
nehas1jan26-Feb-13 18:35
membernehas1jan26-Feb-13 18:35 
GeneralRe: streaming? Pin
dogancanbakir26-Feb-13 23:03
memberdogancanbakir26-Feb-13 23:03 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150901.1 | Last Updated 16 Jan 2013
Article Copyright 2013 by nehas1jan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid