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 !




How to Create a ThumbImage from any exisisting Image


Posted Date: 28 Jun 2005    Resource Type: Code Snippets    Category: C# Syntax

Posted By: Naveen Dhawan       Member Level: Bronze
Rating:     Points: 10



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

}




Responses

Author: harminder singh    28 Jun 2005Member Level: Bronze   Points : 0
This very nice article for Creating thumbnail Images.


Author: Pardeep Singh    28 Jun 2005Member Level: Gold   Points : 0
Very Nice I was Just looking for that


Author: Vikas Monga    28 Jun 2005Member Level: Bronze   Points : 0
its realy a valueable code. its solve problems for conversion...




Author: GodSpeed    23 May 2008Member 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 2008Member Level: Gold   Points : 2
this is really a nice code ,help full to me very much


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
ThumbImage  .  

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.
Previous Resource: Data grid view multiple checkbox selection
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

email fax service

Contact Us    Privacy Policy    Terms Of Use