C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Creating Dynamic Thumbnail Images through ASP.NET


Posted Date: 08 Sep 2005    Resource Type: Articles    Category: .NET Framework
Author: Noorul AmeenMember Level: Bronze    
Rating: 1 out of 5Points: 7



Introduction


While uploading Images, we always show that image to the user by reducing the height and width of the Image. So the Image is seen shrinked, which is annoying. Now we can create thumbnail size of the Original image which will have the same quality as the original image.


Place the Controls


Open a webform and place a File Field(File1), mark it as Server Control and add a Command button(cmdUpload). Also add a Image Control(Image1).


The method 'NewImageSize' will get the height and width of the original image and converts it to base 75 pixels.


private Size NewImageSize(int OriginalHeight,int OriginalWidth)
{
Size NewSize;
double tempval;
if (OriginalHeight>75 && OriginalWidth>75)
{
if (OriginalHeight>OriginalWidth)
tempval=75.0/Convert.ToDouble(OriginalHeight);
else
tempval=75.0/Convert.ToDouble(OriginalWidth);

NewSize=new

Size(Convert.ToInt32(tempval*OriginalWidth),Convert.ToInt32(tempval*OriginalHeight));
}
else
NewSize=new Size(OriginalWidth,OriginalHeight);

return NewSize;
}



Write Code at Click Event



Paste the following code in the click event of the Command Button(cmdUpload).


private void cmdUpload_Click(object sender, System.EventArgs e)
{
string FileExtension=Path.GetExtension(File1.PostedFile.FileName);

string ThumbnailPath=Server.MapPath("SomeFolderinYourApplication"+FileName+FileExtension);

System.Drawing.Image Img=System.Drawing.Image.FromFile(File1.PostedFile.FileName);

Size ThumbNailSize=NewImageSize(Img.Height,Img.Width);

System.Drawing.Image ImgThnail=new Bitmap(Img,ThumbNailSize.Width,ThumbNailSize.Height);

ImgThnail.Save(ThumbnailPath,Img.RawFormat);
File1.PostedFile.SaveAs(ImagePath);

Image1.ImageUrl=ThumbnailPath;

Img.Dispose();
ImgThnail.Dispose();

}


Towards the End


Thats it. Compile the application and run the web form. Upload the image throught File Field and click on the Upload button.

You can see the thumbnail size image in the folder you specified at 'SomeFolderinYourApplication'.




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

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: Which language to choose C# or VB ?(Part2)
Previous Resource: Understanding Delegates in C#
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use