| Author: Nagarajan 04 Aug 2008 | Member Level: Gold | Rating: Points: 6 |
In the Image Tag specify the URL as below
<img src="ThumbnailGen.aspx?img=xyz.jpg" />
Create a file ThumbnailGen.aspx as below
public class ThumbnailGen : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { // get the file name from querystring string file = Request.QueryString["img"];
// create an image object, System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file));
// create the actual thumbnail image // by default the thumbnail is configured to 64x64 System.Drawing.Image thumbnailImage = image.GetThumbnailImage(64, 64, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
// make a memory stream to work with the image bytes MemoryStream imageStream = new MemoryStream();
// save 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 Response.ContentType = "image/jpeg"; Response.BinaryWrite(imageContent); }
/// <summary> /// Required, but not used. /// This is a GetThumbnailImageAbort handler /// </summary> /// <returns>true</returns> public bool ThumbnailCallback() { return true; // nothing is done here } }
The Thumbnail is configured by default to 64 x 64, if required it can be sent thru querystring along with the img file name and image can be generated as per that.
Happy Coding.
|
| Author: lavanya 05 Aug 2008 | Member Level: Gold | Rating: Points: 4 |
HAI nagarajan, in default4.aspx.cs System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file)); in the above line i am getting an error.. like file not found exception i have taken in source like this img src="Default4.aspx?img="~/00759000420.jpg" alt="hai" help me plz
|
| Author: Nagarajan 12 Aug 2008 | Member Level: Gold | Rating: Points: 4 |
Sorry Lavanya, for the very delay replay, i haven't check the forum for a while, next time pls sent it as a message or to my mailid
problem might be with img url instead of specifying img src as "~/00759000420.jpg", try giving a path something like, "/website/Images/00759000420.jpg" or a relative path with reference to the current aspx file location.
|