C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Thumbnail Image in ASP.Net forms


Posted Date: 12 Aug 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: NagarajanMember Level: Gold    
Rating: Points: 10



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

///
/// Required, but not used.
/// This is a GetThumbnailImageAbort handler
///

/// true
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.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Thumbnail images  .  Thumbnail in asp.net  .  Image in asp.net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Access database thorough class files
Previous Resource: Show video like you tube in asp.net page
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use