A function that creates a thumb image from any one existing image.
Points to note:
1. you must know how to prevent escape chracters i.e. with "@" sign
eg. @"C:\Documents and Settings\naveen\My Documents\My Pictures\abc.gif"
2. you must gives the permissions to folder in which you wish to save a thumbnail image.
public void CreateThumbNail(string DesiredImageNameForThumbImage,string OrignalImagePath,string ThumbImageTargetPath,string ContentType,Int32 ThumbImageHeight, Int32 ThumbImageWidth) { System.Drawing.Image OrignalImage,Thumb; string sPath; Int32 OrignalImageHeight,OrignalImageWidth; IntPtr ptr = new IntPtr(); sPath = ThumbImageTargetPath + "/" + DesiredImageNameForThumbImage + "." + ContentType; OrignalImage = System.Drawing.Image.FromFile(OrignalImagePath); OrignalImageHeight = OrignalImage.Height; OrignalImageWidth = OrignalImage.Width ; if ( (OrignalImageHeight > ThumbImageHeight) || (OrignalImageWidth > ThumbImageWidth)) { Int32 diffHeight,diffWidth; diffHeight = OrignalImageHeight-ThumbImageHeight; diffWidth = OrignalImageWidth-ThumbImageWidth; Double ScaleFactor; if (diffHeight > diffWidth) ScaleFactor = (ThumbImageHeight / OrignalImageHeight); else ScaleFactor = (ThumbImageWidth / OrignalImageWidth ); OrignalImageHeight *= Convert.ToInt32( ScaleFactor); OrignalImageWidth *= Convert.ToInt32(ScaleFactor); Thumb = OrignalImage.GetThumbnailImage(ThumbImageWidth,ThumbImageHeight,null,ptr); Thumb.Save(sPath); Thumb.Dispose (); OrignalImage.Dispose(); } }
|
| Author: harminder singh 28 Jun 2005 | Member Level: Bronze Points : 0 |
This very nice article for Creating thumbnail Images.
|
| Author: Pardeep Singh 28 Jun 2005 | Member Level: Gold Points : 0 |
Very Nice I was Just looking for that
|
| Author: Vikas Monga 28 Jun 2005 | Member Level: Bronze Points : 0 |
its realy a valueable code. its solve problems for conversion...
|
| Author: GodSpeed 23 May 2008 | Member Level: Silver Points : 2 |
really helpful, no comments and no explanation as to what is going on. Not really a tutorial is it?
|
| Author: vijetha 29 May 2008 | Member Level: Gold Points : 2 |
this is really a nice code ,help full to me very much
|