AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=402&pId=-1
ASP.NET images: Thumbnails
page
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 14767/ 24

ASP.NET images: Thumbnails

In previous parts to this tutorial I showed you how we can use the system.drawing namespaces to build images on the fly, load and modify images and return them to the user. This article shows the algorithm for resizing an image while keeping its aspect ratio.

The script returns an image which will fit into a thumbnail size I chose at random of 200x200 pixels.

View the sourcecode

In the previous example we specified the size of the image to output on the querystring. This time we call a new function which returns what the size should be, called "NewThumbSize" which returns a "size" object (basically an object containing a height and width).

The "NewThumbSize" function checks to see if the image is portrait or landscape, then works out the multiplier (the division of our arbitrary 200 pixels and the height or width). There is an obvious flaw here that the image could end up bigger than it started, I will leave this as an exercise for the reader ;O)

Once we have the new size using the above multiplier, we return the new size object and use it to set the width and height of the image to output.


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 6:22:48 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search