Creating a thumbnail image dynamically - Hendrik Swanepoel

Hendrik Swanepoel

Creating a thumbnail image dynamically

I was really surprised about how easy this is. The last time I played with the System.Drawing namespace was when I dynamically created images when I first started playing around with ASP.Net.

I'm currently including functionality into a product that allows it to display images on the server as thumbnails, and these thumbnails needs to be dynamically generated. The following snippet shows how to dynamically generate a thumbnail and display it.

        public bool ThumbnailCallBack()
        {
            return false;
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            System.Drawing.Image.GetThumbnailImageAbort callback = 
                new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallBack);
            System.Drawing.Image im = System.Drawing.Image.FromFile(Server.MapPath("Sample.jpg")); 
            System.Drawing.Image thumb =  im.GetThumbnailImage(50, 50, callback, IntPtr.Zero);
            thumb.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Posted: Jun 08 2004, 08:44 AM by hendrik | with 1 comment(s)
Filed under:

Comments

arjun said:

nice
# April 13, 2005 8:06 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: