satheesh babu

satheesh babu

  • NA
  • 128
  • 312.1k

saving picture using web cam

Feb 5 2009 1:03 AM

Hi All,

            Here i am capturing picture to imgage control from Web Cam and saving to data base.

I am doing this successfully using below code.
But when i press my save button --> after saving the data into data base picture is showing in image control and after that all my controls in the form are not showing(only picture is showing)

I want to show all my previous controls in my page as it is.

here is my code

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Net;
using System.Data.SqlClient;

 short nQuality = 45;

       
        //Shout a picture from my webcam

        CAMSERVERLib.Camera cam = new CAMSERVERLib.CameraClass();

        byte[] picture = (byte[])cam.GrabFrame(nQuality);

       // byte [] mbarr = new byte[Convert.ToInt32(picture.Length)];

        //Add the hour to the jpeg picture

        MemoryStream ms = new MemoryStream(picture);
        Bitmap bmp = new Bitmap(ms);

        Graphics g = Graphics.FromImage(bmp);
ImageCodecInfo[] icf = ImageCodecInfo.GetImageEncoders();

        EncoderParameters encps = new EncoderParameters(1);
        EncoderParameter encp = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,(long)nQuality);

        //Set quality

        encps.Param[0] = encp;
       

        bmp.Save(Response.OutputStream, icf[1], encps);

        //bmp.Save(string img,ImageFormat.Jpeg);                    

        g.Dispose();
        bmp.Dispose();


        byte[] mbarr = new byte[Convert.ToInt32(picture.Length)];

        SqlConnection conn = new SqlConnection(strConnection);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        conn.Open();

        cmd.CommandText = "insert into imgData(imgID," + " imgName,imgPic) values(@imgID,@imgName,@imgPic)";

        cmd.Parameters.Add("@imgID", SqlDbType.Int, 4);
        cmd.Parameters.Add("@imgName", SqlDbType.VarChar, 50);
        cmd.Parameters.Add("@imgPic", SqlDbType.Image);

        cmd.Parameters["@imgID"].Value = Convert.ToInt32(TextBox1.Text);
        cmd.Parameters["@imgName"].Value = TextBox2.Text;
        cmd.Parameters["@imgPic"].Value = mbarr;

        cmd.ExecuteNonQuery();

Please help me out how to enable controls after picture is capturing.

thank you....


Answers (2)