Hi,

I would like to capture the image using WebCam and store it in database. I am using ASP.NET 3.5, C#, Visual Studio 2008, SQL Server 2008, Windows Vista Business (O.S), IIS 7.0 and IE 7.0. I want to integrate WebCam functionality in my Web Application. My requirement is, the end user can view the image (i.e., preview from the WebCam) in the Web page using ActiveX Control (in my case videocapx.ocx is the ActiveX Control). And on clik of "Capture" button, the image has to be capture and stored in database. For this I have installed "VideoCapX" software. I am using "ZEBRONICS" WebCam to capture images. Its model number is "Eagle's eye ZEB-480WC". How can I integrate "videocapx.ocx ActiveX Control" in my web page, so that end user can preview the image.

Please help me out. It is very urgent. Thanks inadvnce.

OR

Is there any way to capture image using webcam @ client side.
In my case both Client & Server are same.
How can I acheive this.
If it is possible using some other way, please give your suggestions.

Thanks & Regards,
VKK Reddy.

Dani AI

Generated

asked how to preview/capture a webcam image in an ASP.NET 3.5 app. Two practical paths exist: keep the ActiveX route (IE-only, requires a client-side OCX installed and registered) or use a modern browser API (recommended where possible). Note that Internet Explorer’s desktop app was retired for many Windows builds on June 15, 2022 and ActiveX is a legacy approach with limited browser support, so plan for compatibility or migration. (learn.microsoft.com)

If continuing with the OCX (legacy / controlled environment): the control must be installed and registered on each client, the HTML should embed it with an <object> tag (classid or progid), and IE must be configured to allow the control (ActiveXFiltering off, allow signed controls, etc.). Watch for 32-bit vs 64-bit IE mismatches and UAC/registration requirements on Vista/Win7. Example embed (replace the CLSID/progid and params with values from the OCX vendor):

<object id="webcam" classid="CLSID:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" width="320" height="240">
  <param name="SomeParam" value="...">
</object>

Microsoft documents embedding and ActiveX settings for IE. (learn.microsoft.com)

A more future-proof approach is client-side capture with MediaDevices.getUserMedia(), draw a video frame to a canvas, convert to a data URL, then POST the image to the server. This works cross-browser (modern browsers) and requires HTTPS and explicit user permission. Example capture flow (client JS):

navigator.mediaDevices.getUserMedia({ video: true })
  .then(stream => { video.srcObject = stream; })
  .catch(err => console.error(err));

function capture() {
  const canvas = document.createElement('canvas');
  canvas.width = video.videoWidth; canvas.height = video.videoHeight;
  canvas.getContext('2d').drawImage(video, 0, 0);
  const dataUrl = canvas.toDataURL('image/jpeg'); // send this to server
  fetch('/saveimage.aspx', { method: 'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({ image: dataUrl }) });
}

See the MediaDevices.getUserMedia docs for details and constraints. (developer.mozilla.org)

Server-side (ASP.NET 3.5) accept the posted data URL, strip the prefix, Convert.FromBase64String, and insert into a VARBINARY(MAX) column (or consider FILESTREAM for large files in SQL Server 2008+). Minimal SQL and C# examples:

-- SQL
CREATE TABLE Photos (Id INT IDENTITY PRIMARY KEY, ImageData VARBINARY(MAX), ContentType NVARCHAR(50), Created DATETIME DEFAULT GETDATE());
[WebMethod]
public static int SaveImage(string dataUrl) {
  var comma = dataUrl.IndexOf(',');
  var base64 = (comma >= 0) ? dataUrl.Substring(comma+1) : dataUrl;
  byte[] bytes = Convert.FromBase64String(base64);
  using(var cn = new SqlConnection(connStr))
  using(var cmd = new SqlCommand("INSERT INTO Photos (ImageData,ContentType) VALUES(@img,@ct); SELECT SCOPE_IDENTITY()", cn)) {
    cmd.Parameters.Add("@img", SqlDbType.VarBinary, -1).Value = bytes;
    cmd.Parameters.Add("@ct", SqlDbType.NVarChar, 50).Value = "image/jpeg";
    cn.Open();
    return Convert.ToInt32(cmd.ExecuteScalar());
  }
}

Store images safely (validate size/type), prefer parameterized SQL, and document client install/registry steps if you must keep ActiveX. linked an example earlier; the getUserMedia path below is the recommended, cross-browser option where client environment allows it. (learn.microsoft.com)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.