Skip to main content

Capture and save images from Web camera using C# and ASP.NET


In this article with some C# sample, I am going to explain how to capture and save image from web camera.

This web camera capturing and storing is implemented using flash on the front end and C# on the back end. You can easily embed this flash file into your web page and record images from the webcam.

Requirements to capture images from webcam using C#:


If you want to implement this functionality you need to install the latest flash player and have a working web camera.

Steps to capture webcam images using C# and ASP.NET:


1) Create a new web application project and copy the WebcamResources folder from the attachments.

2) Create a new page named "Default.aspx" page add the following code,

<object width="405" height="190"
  param name="movie" value="WebcamResources/save_picture.swf"
  embed src="WebcamResources/save_picture.swf" width="405" height="190" >
</object>
The above code is to place the flash object in your webpage, which is used to capture images from the webcam.

3) Create another ASP.NET web page and name it "ImageConversions.aspx" 

This page name is should be of same name if you use the attached swf file. Whenever the capture image button is clicked, then it redirectd
to "ImageConversions.aspx" page. So the file name matters!

4) In this ASP.NET page, add the following C# code in the pageload or create a
separate method.

string strPhoto = Request.Form["imageData"]; //Get the image from flash file
byte[] photo = Convert.FromBase64String(strPhoto);
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();

Above example written in C# will convert the byte code into image and store 
the image in local C: drive.

Comments

Popular posts from this blog

Asp.Net Web API

What is ASP.NET Web API? ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.   Difference between ASP.NET Web API and WCF Web AP I is a Framework to build HTTP Services that can reach a board of clients, including browsers, mobile, IoT Devices, etc. and provided an ideal platform for building RESTful applications. It is limited to HTTP based services. ASP.NET framework ships out with the .NET framework and is Open Source. WCF i.e. Windows Communication Foundation is a framework used for building Service Oriented applications (SOA) and supports multiple transport protocol like HTTP, TCP, MSMQ, etc. It supports multiple protocols like HTTP, TCP, Named Pipes, MSMQ, etc. WCF ships out with the .NET Framework. Both Web API and WCF can be self-hosted or can be...

Creating package in Oracle Database using Toad For Oracle

What are Packages in Oracle Database A package is  a group   of procedures, functions,  variables   and  SQL statements   created as a single unit. It is used to store together related objects. A package has two parts, Package  Specification  and Package Body.