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
- Latest Flash Player
- Web Camera
You need to do
The following is what you need to do:
- Copy the "WebcamResources" into your new application.
- Add the following code to your Default.aspx page:This code will place your Flash object in your web page for capturing the image from the webcam.
- <object width="450" height="200"
- param name="movie1" value="WebcamResources/save_picture.swf"
- embed src="WebcamResources/save_picture.swf" width="450" height="200" >
- </object>
- Create one more page named "ImageConversions.aspx".
- Add the following code into the ImageConversion.aspx file for the page load event:
- 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 code above will convert the bytes to an image and save the image in the C drive.
Enjoy!

r bozPosted Jun 4, 2023, 10:08 AM
Project not working. Thanks for fake project.
sanaullah malikPosted Jul 22, 2018, 11:11 PM
Hi neha...its a veru good article ... but when i deployed it on IIS on windows server 2008r2 the client's camera is not accessible... although the code works fine on localhost...Kinldy guide me how to get client's camersa access after deploying my website on IIS...
Ashraful IslamPosted Jan 29, 2018, 10:54 PM
Its working on my source code. but whenever i publish in iis its not working. why? plz help me.
Rosemarie CanhamPosted Dec 15, 2017, 2:01 AM
Hi Neha, Thank You, just having an issue, when i publish my site it is tying to access the servers camera not the clients, looked at many examples , i know how to save it to the database or a location . I need to know how i can access the clients web camera to take the picture... thank you so much your help is much appreciated
Harish MadaanPosted Oct 10, 2017, 6:17 AM
How to increase image size
Muhammad NadeemPosted Oct 1, 2017, 1:07 AM
Hi neha your topic is incomplete. we don't get any idea from it. but it's ok
Harish MadaanPosted Jun 1, 2017, 8:30 AM
Hi Neha, your code showing image on web form but not storing it on folder and how can i get image name on submit button.
birju gohelPosted May 1, 2015, 4:23 AM
Hi Neha . I have implemented the same functionality. But Not Store in Folder and generate Error (Value cannot be null. Parameter name: s) How to Solve , And Other Think : capturing image Default.aspx is running but as soon as I clicked Capture how Image Conversion.aspx is called? Pleas How To Solve this Give me Way ..
kuldeep patelPosted Jan 1, 2015, 11:38 PM
Thnx Neha. your code is working fine for me. Just had query that every time it is asking for allow flash player. is there any workaround for it to directly allow it.
prabhu pPosted Sep 2, 2014, 2:11 AM
its working but while saving in E: image its replace with existing older captured image. at a time in folder only one image that lastly took
Raghvendr SinghPosted Aug 4, 2014, 4:44 AM
Hi Neha Your code is working fine.everything is OK but there is some confusion.In the project for capturing image Default.aspx is running but as soon as I clicked Capture how ImageConversion.aspx is called?
Saineshwar BageriPosted Apr 16, 2014, 12:15 AM
http://www.c-sharpcorner.com/UploadFile/4d9083/capturing-image-from-web-cam-in-Asp-Net/
Sandeep GowdaPosted Apr 2, 2014, 3:08 AM
Hi Neha,
ashish pujaraPosted Mar 6, 2014, 8:29 AM
Hi Neha . I have implemented the same functionality. everything is working in my local machine but when i publish my source code and capturing image from client machine then image is not stored at server side. As per your mention code you are saving image at C:\\capture.jpg but i given server.mappath('a.jpg')
mikhil acholkarPosted Feb 18, 2014, 3:59 AM
Hi Neha the code is executing fine not showing any error but the image is not storing in the specified location(c:\\capture.jpg) please help me.
Marreddy BasaniPosted Feb 7, 2014, 2:50 AM
Excellent App
chakradhar nPosted Jan 25, 2014, 8:06 AM
it's working fine thanx madam
Avinash OjhaPosted Nov 29, 2013, 6:39 AM
Hi Neha , thanks for posting such a nice article , I am trying to use this in my web solution to capture images from webcam or cellphone , But flash player does not work properly ,Is this a version problem or what ever this is, please instruct me regarding this , I am using 11.9 version of flash player
Shohel RanaPosted Nov 13, 2013, 2:20 AM
but i want to image size will be portrait...
iman aliPosted Jul 31, 2013, 2:22 PM
While i publish this code on IIS i am enable to save image i dont know why ??? Can you plz help me
wasim tPosted Jul 26, 2013, 1:36 AM
WebcamResources how to add..i have download this and try to run but Request.Form["imageData"] is null can you plz help me out
Former memberPosted Jul 24, 2013, 8:53 AM
Thanks it works fine..... Great article....
Yasir JaseemeditedPosted May 20, 2013, 9:14 AMEdited May 20, 2013, 9:17 AM
is there group communication with minimum 2 persons can possible with this project.
Neha SharmaPosted Mar 11, 2013, 3:43 AM
if you want changes in swf file you need to work with flash
carlos robertoPosted Mar 9, 2013, 5:47 PM
Thanks Neha. I understand. It just that I want to capture 3 different pictures by clicking the Capture Button. If I do a loop inside the ImageConversions.aspx.cs it captures the same picture 3 times. Since the Capture Button is a swf file, I don't know how to do this. Do you know how to do it?
Neha SharmaPosted Mar 9, 2013, 12:47 AM
Hi carlos,i can understand,web cam capture image consist more and more logic and more and more different kind of requirements.In my this article i just explained and tried to explain "How to be familiar with web cam" .These codes and points may be fulfill your all type of requirement but may be some time you need some extra effort to implement something with web cam or to turn.Anyways What are you asking you can do when you create time interval and then pass a loop to save and show the image @ each interval time.Hope you ll understand what i am saying.thx :)
carlos robertoPosted Mar 8, 2013, 1:00 PM
Hi again Neha...I will try to explain better about the WebCam Image Capture. When I click the Capture Image Button, I want to take the picture (I have no problem doing that) but after 5 seconds automatically I want to take another picture and after 5 seconds another one...But only by clicking one time the Capture Image button... Do you have any idea on how can it be possible? Thanks in advance. I apologize for being too insistent.
Neha SharmaPosted Mar 8, 2013, 5:44 AM
Yours all time welcome,but may be i am unable to understand your exact problem but in forum section other people also will be there to solve this and try to post there screenshots also with what you want and what you are getting there.
Satinder SinghPosted Mar 8, 2013, 5:37 AM
Thank for your precious solution, But it didnt solve my problem yet.
Neha SharmaPosted Mar 8, 2013, 5:34 AM
ok!post this in to c#corner forum section .
Satinder SinghPosted Mar 8, 2013, 5:32 AM
i checked and on beduggin there is not error, nor any exception, the image is also created with unique name on folder.
Neha SharmaPosted Mar 8, 2013, 5:29 AM
you are doing something wrong here you can only check it by adding breakpoints there and debug that to know what is wrong there.
Satinder SingheditedPosted Mar 8, 2013, 5:27 AMEdited Mar 8, 2013, 5:30 AM
On CeatePhoto() method here i set imagepath with name in session variable. _________________________________________________________________________________________________________ path = "~/WebcamResources/" + DateTime.Now.Ticks + "Webcam1.jpg"; Session["getPath"] = path;_________________________________________________________________________ On default.aspx _______________________________________________ On page_load()string b = Session["getPath"].ToString();Image1.ImageUrl = b; _______________________________________________________________________________________________________ Here its not working, it diplay the old image and on page refresh get the right image
Neha SharmaeditedPosted Mar 8, 2013, 5:20 AMEdited Mar 8, 2013, 5:22 AM
simply when the whole work done as i explained in this article you can take that saved Image name to show on the Image control.. and yes it is looking weird anyways not your fault..
Satinder SinghPosted Mar 8, 2013, 5:19 AM
Sorry for posting my code with improper formatting
Satinder SingheditedPosted Mar 8, 2013, 5:17 AMEdited Mar 8, 2013, 5:21 AM
I did this minor changed in ur code. string strPhoto = Request.Form["imageData"]; //Get the image from flash filebyte[] photo = Convert.FromBase64String(strPhoto);path = "~/WebcamResources/" + DateTime.Now.Ticks + "Webcam1.jpg";Session["getPath"] = path;FileStream fs = new FileStream(Server.MapPath(path), FileMode.OpenOrCreate, FileAccess.Write);// FileStream fs = new FileStream("C:\\Webcam.jpg", FileMode.OpenOrCreate, FileAccess.Write);BinaryWriter br = new BinaryWriter(fs);br.Write(photo);br.Flush();br.Close();fs.Close(); THEN on Default.aspx page where my image control i code this on Pageload. protected void Page_Load(object sender, EventArgs e){if (Session["myCounter"] != null){string a = Session["myCounter"].ToString();string b = Session["getPath"].ToString();Image1.ImageUrl = b;}}
Neha SharmaPosted Mar 8, 2013, 5:11 AM
satinder please debug your application and catch image name and image path there,and write code there to display that in your asp.net image control or you can do this in the last by add somce code lines to display image where you are saving that in local PC.got it?
Neha SharmaPosted Mar 8, 2013, 5:11 AM
satinder please debug your application and catch image name and image path there,and write code there to display that in your asp.net image control or you can do this in the last by add somce code lines to display image where you are saving that in local PC.got it?
Satinder SingheditedPosted Mar 8, 2013, 5:08 AMEdited Mar 8, 2013, 5:09 AM
Thanks for replying me. Here two pages 1) Default.aspx page 2) ImageConversions.aspx On Default.aspx i add one asp.net IMAGE CONTROL. While captured the image from webcam using your above code it redriect page on ImageConversions.aspx and call CreatePhoto() on page load then return back to Default.aspx. At the same time i want to diplay that captured image in my asp.net image control. Well where i can send you the screenshot pls let me now am newbie
Neha SharmaPosted Mar 8, 2013, 4:06 AM
Hi satinder,thx for your nice words,what ar eyou saying i am unable to getting can you please elaborate it more or if you provide me some screenshot ll be best for understanding thx
Satinder SinghPosted Mar 8, 2013, 4:00 AM
Hi neha, First of all thanks for posting such a nice article, I used it in one of my project, but i have some problem. Actually in default.aspx page i added one image control and try to set image src as which we captured from webcam. Here i need to refresh my page to get the proper image src else it will display the previous image. I tried my self to save url on Session but this didnt worked for me, then i send in QueryString it also not worked, Can you help me
Neha SharmaPosted Mar 8, 2013, 12:47 AM
hi Carlos!It ll be ma pleasure to help you,but to understand what are you saying i need some screen shots or want to see your screen via TV or something which ll you prefer.
carlos robertoeditedPosted Mar 7, 2013, 1:12 PMEdited Mar 7, 2013, 3:30 PM
Thanks Neha, What I'm Trying to do is to click the Capture Button and then with a "For" cycle, capture 4 different pictures.... I'm having problems calling the swf file so it can capture this 4 pictures by clicking the capture button only once..Do you have any idea how?
Neha SharmaPosted Mar 7, 2013, 12:27 AM
Hi carlos,you can call the same picture in other image control boxes or can create one more control there.
carlos robertoPosted Mar 6, 2013, 6:42 PM
Hi, Neha, How can I take more than 1 picture by clicking the button only one time? Thanks in advance
Neha SharmaPosted Feb 27, 2013, 12:33 AM
yes snn!!
snn kctrkPosted Feb 26, 2013, 12:38 PM
Very good.. do you plan for voice ?
Neha SharmaPosted Feb 20, 2013, 2:03 AM
thx :)
Vithal WadjePosted Feb 13, 2013, 11:20 PM
super one ,keep posting
Rishikesh Kumar SinghPosted Feb 13, 2013, 11:18 PM
good one..