Click here to Skip to main content
Click here to Skip to main content

Capture images using web camera in ASP.NET 4.5

, 16 Jan 2013 CPOL
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
Follow on   Twitter   Google+

Comments and Discussions

 
Questioncode not working . PinmemberMember 1095387415-Jan-15 5:30 
Questionhow to capture image from webcam without showing User in asp.net c# Pinmemberaminch3276-Jan-15 23:51 
QuestionImage not save in folder (online) PinmemberPrasanna Mhamane14-Nov-14 2:12 
AnswerRe: Image not save in folder (online) Pinmembernehas1jan14-Nov-14 2:14 
QuestionNeed to change filename by taking name from another page PinmemberMember 880009713-Nov-14 2:12 
AnswerRe: Need to change filename by taking name from another page Pinmembernehas1jan14-Nov-14 2:16 
GeneralRe: Need to change filename by taking name from another page PinmemberGauravSotani2714-Nov-14 2:37 
AnswerRe: Need to change filename by taking name from another page PinmemberGauravSotani2714-Nov-14 2:36 
QuestionImage not save in folder (online) PinprofessionalReshma Khaire11-Nov-14 1:37 
AnswerRe: Image not save in folder (online) Pinmembernehas1jan11-Nov-14 1:42 
GeneralRe: Image not save in folder (online) PinmemberMember 1122623611-Nov-14 19:11 
GeneralRe: Image not save in folder (online) Pinmembernehas1jan14-Nov-14 2:17 
GeneralRe: Image not save in folder (online) PinmemberMember 1095387415-Jan-15 5:32 
GeneralWebCam Device PinmembertejasGhadge11-Oct-14 6:51 
Questionhere is good example using Jquery plugin for Asp.net Pinmembersaineshwar15-Apr-14 19:13 
QuestionCan we use different file name , instead of ImageConversion.aspx ? Pinmembernayeemkhan2427-Feb-14 21:47 
AnswerRe: Can we use different file name , instead of ImageConversion.aspx ? PinmemberImran_hus6-Jun-14 21:39 
Questionimage size Pinmemberagnushallard18-Feb-14 3:54 
Questionnot getting the file in desired path or in any path please give us where is it going wrong Pinmemberviral198620-Jan-14 20:20 
AnswerRe: not getting the file in desired path or in any path please give us where is it going wrong Pinmembernehas1jan20-Jan-14 20:23 
QuestionImage is not saving in C drive... PinmemberMember 1019895822-Dec-13 20:18 
QuestionCan I avoid the "Permissions window"? PinmemberIvanov Correa15-Dec-13 21:24 
AnswerRe: Can I avoid the "Permissions window"? PinmemberIvanov Correa15-Dec-13 21:48 
QuestionThanks! - Worked "out of the box" PinmemberIvanov Correa8-Dec-13 16:16 
Questionscanner and tab device for signature PinmemberFaisal suleman18-Nov-13 21:37 

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
Web04 | 2.8.150129.1 | Last Updated 16 Jan 2013
Article Copyright 2013 by nehas1jan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid