Monday, March 28, 2011

Create thumbnail in c#

Many of times we requires to create a thumbnails images or we can say we wants to create a new image from existing one with different height and width. to do so below code will help you:

First of all create an object of image class and pass image url in it:


System.Drawing.Image objImage = System.Drawing.Image.FromFile(strFilename) ;


Now create thumbnail:

System.Drawing.Image.GetThumbnailImageAbort callback ;
callback = null ;
int shtWidth=180;
int shtHeight=130;
System.Drawing.Image objThumbnail = objImage.GetThumbnailImage(shtWidth , shtHeight, callback, System.IntPtr.Zero) ;  


Now save newly created thumbnail image to required format:


objThumbnail.Save("thumbfilename", System.Drawing.Imaging.ImageFormat.Jpeg ) ;



Solution By: Rajesh Rolen

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates