First of all thanks fpr your this article sir... @MudassarKhan
https://www.aspsnippets.com/Articles/Capture-Image-Photo-from-Web-Camera-Webcam-in-ASPNet-using-C-and-VBNet.aspx
But i also want to save image path and image name into databse for the user who capture the image and want to use it for further process and i am trying to do this. I am saving the imagePath and imageName string into databse but it's not working.
and i also want to show processing between caapturing and showing image becuse it takes sometime to capture and show image.
So How can these things possible..? Please explain...
Thanks
string imageName, imagePath;
string globalUserName, globalPass;
string connstr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
Error.Text = "";
if (!this.IsPostBack)
{
if (Request.InputStream.Length > 0)
{
using (StreamReader reader = new StreamReader(Request.InputStream))
{
string hexString = Server.UrlEncode(reader.ReadToEnd());
imageName = DateTime.Now.ToString("dd-MM-yy hh-mm-ss");
imagePath = string.Format("~/Captures/{0}.png", imageName);
File.WriteAllBytes(Server.MapPath(imagePath), ConvertHexToBytes(hexString));
Session["CapturedImage"] = ResolveUrl(imagePath);
}
}
}
}
private static byte[] ConvertHexToBytes(string hex)
{
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < hex.Length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
[WebMethod(EnableSession = true)]
public static string GetCapturedImage()
{
string url = HttpContext.Current.Session["CapturedImage"].ToString();
return url;
}
protected void Submit_image_Click(object sender, EventArgs e)
{
if (Session["CapturedImage"] == null)
{
Error.Visible = true;
Error.Text = "Image not captured, Please try again";
}
else
{
SqlConnection con = new SqlConnection(connstr);
con.Open();
Response.Write(imagePath);
string imgDetails = "UPDATE Student SET ImageName = @IName where Email = @Ename AND Pass = @Pass ";
SqlCommand com = new SqlCommand(imgDetails, con);
com.Parameters.AddWithValue("@IName", imageName);
com.Parameters.AddWithValue("@Ename", globalUserName);
com.Parameters.AddWithValue("@Pass", globalPass);
com.ExecuteNonQuery();
Response.Write("Hello");
}