User-1618958993 posted
Hi
I am using a Datalist to Bind some ImageButton at runtime. I made the size smaller to show the image small but it's not a proper way to make thumbnail. Now I tried for that but no result found..... I am submitting the HTML and Codes to debug it. Please help
me. It's an very urgent task for me..
HTML Code : <asp:ImageButton
runat="server"
ImageUrl="http://mysite.com/demo/MakeThumbnail.aspx?file=fall800.jpg"/>
Code Behind MakeThumbnail.aspx.cs
public
class MakeThumbnail : System.Web.UI.Page
{
private
void Page_Load(object sender, System.EventArgs e)
{
// getting the file name --
string file = Request.QueryString["file"];
// creating an image object, using the filename we just retrieved
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file));
// creating the actual thumbnail image
System.Drawing.Image thumbnailImage = image.GetThumbnailImage(64, 64,
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
// making a memory stream to work with the image bytes
MemoryStream imageStream =
new MemoryStream();
// putting the image into the memory stream
thumbnailImage.Save(imageStream, System.Drawing.Imaging.Imageformat.Jpeg);
// making byte array the same size as the image
byte[] imageContent =
new Byte[imageStream.Length];
// rewinding the memory stream
imageStream.Position = 0;
// loading the byte array with the image
imageStream.Read(imageContent, 0, (int)imageStream.Length);
// returning byte array to caller with image type
Response.ContentType = "image/jpeg";
Response.BinaryWrite(imageContent);
}
public
bool ThumbnailCallback()
{
return
true;
}
}
Please correct it if there is any mistakes in codes...