Click here to Skip to main content
14,601,061 members

Show thumbnail images in image box

shikha_14 asked:

Open original thread
i have stored image path in database. when i access these images from database i converted them to thumbnail so that images to be displayed in image box should not be distorted. i have converted the image in thumbnail but am not able to show that thumbnail to image box with in the same page .The thumbnail is stored in byte array and can response to next page but i want to show image in that page only when user clicks on the button show. please suggest something.

code is:

protected void Button1_Click(object sender, EventArgs e)
  {
     SqlDataAdapter adp = new SqlDataAdapter("select pic from images where userid=" + 1, con);
      DataSet ds = new DataSet();
      adp.Fill(ds);

      System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(ds.Tables[0].Rows[0][0].ToString()));

      // create the actual thumbnail image
      System.Drawing.Image thumbnailImage = image.GetThumbnailImage(900,900, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);


      // make a memory stream to work with the image bytes
      MemoryStream imageStream = new MemoryStream();

      // put the image into the memory stream
      thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);

      // make byte array the same size as the image
      byte[] imageContent = new Byte[imageStream.Length];

      // rewind the memory stream
      imageStream.Position = 0;

      // load the byte array with the image
      imageStream.Read(imageContent, 0, (int)imageStream.Length);

      // return byte array to caller with image type

      byte[] bt;
      Response.ContentType = "image/jpeg";
      bt = ((byte[])imageContent);


      Response.BinaryWrite(bt);

      //Response.BinaryWrite(imageContent);

  }
  public bool ThumbnailCallback()
  {
      return true;
  }


[edit]Code block added - OriginalGriff[/edit]
Tags: ASP.NET

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100