Click here to Skip to main content
15,886,724 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

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

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 http://www.codeproject.com/info/cpol10.aspx.



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