Capture image from WebCam and display in another page using C# and VB.Net in ASP.Net

Last Reply 3 months ago By pandeyism

Posted 3 months ago

Hi Team,

With reference to below link.

Capture Image (Photo) from Web Camera (Webcam) in ASP.Net using C# and VB.Net

I want to capture image from OpenWebcam.aspx (camera will open in this form) and show captured image in ShowImage.aspx Image box.

 

Posted 3 months ago Modified on 3 months ago

Hi Waghmare,

Refer below sample.

You need to capture image path put in session and redirect to your destination page where you want show image and take image control and get image path from session.

HTML

Default.aspx

<asp:FileUpload ID="fuImage" runat="server" />
<br />
<asp:Button Text="Capture" runat="server" OnClick="Capture" />

ShowImage.aspx

<asp:Image ID="imgShow" runat="server" />

Code

C#

Default.aspx.cs

protected void Capture(object sender, EventArgs e)
{
    fuImage.SaveAs(Server.MapPath("~/Captures/") + fuImage.FileName);
    string imagePath = string.Format("~/Captures/" + fuImage.FileName);
    Session["CapturedImage"] = imagePath;
    Response.Redirect("ShowImage.aspx");
}

ShowImage.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    imgShow.ImageUrl = Session["CapturedImage"].ToString();
}

VB.Net

Default.aspx.vb

Protected Sub Capture(ByVal sender As Object, ByVal e As EventArgs)
    fuImage.SaveAs(Server.MapPath("~/Captures/") + fuImage.FileName)
    Dim imagePath As String = String.Format("~/Captures/" & fuImage.FileName)
    Session("CapturedImage") = imagePath
    Response.Redirect("ShowImage.aspx")
End Sub

ShowImage.aspx.vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    imgShow.ImageUrl = Session("CapturedImage").ToString()
End Sub

Screenshot