Click here to Skip to main content
14,641,690 members
Rate this:
Please Sign up or sign in to vote.
See more:
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();

      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);



  public bool ThumbnailCallback()
      return true;

[edit]Code block added - OriginalGriff[/edit]
Updated 1-May-11 4:11am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Please look my answer, how to process binary image in ASP.Net. To display binary formated imange from database[^]

I hope it will help you too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

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