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

Posted by Daniel - 884 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


Leave a Reply


Options for your comment:





Hi, my name is Daniel Nugraha, a single male live on an island called Java, Indonesia. This is the place for me to share my interest in computer programming.

Coffee Break

Comments - Thanks Guys :)

  • Rangga Kusuma: Gan, Tengkiu buat postingan yang sangat berguna. Kebetulan ada project utk bikin sms gateway, dan converter Agan sangat berguna utk...
  • Chuck Norton: I actually went ahead & bolted over to Justin’s Get The Image plugin here: http://justintadlock.com/ar...
  • Chuck Norton: Question: is it possible to insert something like [custfieldimg=”joice1.jpg,15 0,1:1″] into the actual templates instead of...
  • Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
  • tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.