saifullah khan

saifullah khan

  • NA
  • 335
  • 295.6k

Parameter is not valid.

Oct 26 2011 6:39 AM
i have stored jpeg images in database table. now i want to retrieve them. here is the code
MemoryStream stream = new MemoryStream();
            try
            {
                  cnn.Open();
                  cmd = new
                     SqlCommand("select pics from images", cnn);
                  byte[] image = (byte[])cmd.ExecuteScalar();
              
                  stream.Write(image, 0, image.Length);
                  Bitmap bitmap = new Bitmap(stream);
                  Response.ContentType = "image/gif";
                  bitmap.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Bmp);
            }
            finally
            {
                  cnn.Close();
                  stream.Close();
            }
but when i run the application it gives me the following error
Parameter is not valid.
Bitmap bitmap = new Bitmap(stream);
can somebody tells me what i need to correct.

Answers (12)