Resizing image on the fly with ASP.NET using the System.Drawing namespace

Posted by Daniel - 2,324 Views

image resizing with asp.net,system drawing namespace,resizing image on the flyResizing image on the fly with the tradional ASP script is impossible without an external component. But with the release of the .NET Framework, resizing image on the fly has become an easy process.

The System.Drawing namespace provides all the functionalities to do that. Lets get to the point. Following is an example of a sub procedure to resize image and then save it to the specified path:

Sub ResizeThenSaveIt(strSourcePath as string, strSavePath as string, intWidth as integer, intHeight as integer)
Dim objOriginalImage as System.Drawing.Image
Dim objResizedImage as Bitmap
Dim imageFormat as Imaging.ImageFormat

objOriginalImage = System.Drawing.Image.FromFile(strSourcePath)
imageFormat = objOriginalImage.RawFormat
objResizedImage = New Bitmap(objOriginalImage, intWidth, intHeight)
objResizedImage.Save(strSavePath,imageFormat)
End Sub

Just in case you’re curious about how it works, the full code is included with this article, you can download it by clicking here (81 KB)

share this article

Digg del.icio.us Netscape StumbleUpon Yahoo! MyWeb reddit Furl Magnolia Newsvine Technorati SlashDot Blinklist Simpy Google
This post as PDFPosted in: Programming - January 2008 | raw