Click here to Skip to main content
16,019,618 members
Please Sign up or sign in to vote.
4.00/5 (1 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();
      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]
Posted
Updated 1-May-11 4:11am
v2

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900