Click here to Skip to main content
12,830,320 members (46,547 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 25 Nov 2008

Image resizing with

, 25 Nov 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Resizing the very large size images with help of and




Sometime when we are uploading images and if we resize with applying variable size then images are not displayed in good quality. So, this article show how to resize images without scratch the image.


In this article we have to use some drawing methods.

Using the code 

' Create new stream.
' Dim stream As New FileStream(fileName, FileMode.Open, FileAccess.Read)

' Create new image.
Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(Stream)

' Calculate proportional max width and height.
Dim oldWidth As Integer = image.Width
Dim oldHeight As Integer = image.Height
If (CDec(oldWidth) / CDec(oldHeight)) > (CDec(newWidth) / CDec(newHeight)) Then
    Dim ratio As Decimal = CDec(newWidth) / oldWidth
    newHeight = CInt((oldHeight * ratio))
    Dim ratio As Decimal = CDec(newHeight) / oldHeight
    newWidth = CInt((oldWidth * ratio))
End If

' Create a new bitmap with the same resolution as the original image.
Dim bitmap As New Bitmap(newWidth, newHeight, PixelFormat.Format24bppRgb)
bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution)

' Create a new graphic.
Dim graphics__1 As Graphics = Graphics.FromImage(bitmap)
graphics__1.InterpolationMode = InterpolationMode.HighQualityBicubic

' Create a scaled image based on the original.
graphics__1.DrawImage(image, New Rectangle(0, 0, newWidth, newHeight),
                      New Rectangle(0, 0, oldWidth, oldHeight), GraphicsUnit.Pixel)

 ' Save the scaled image.
 bitmap.Save(Server.MapPath("Images/") & strDestinationFileName, image.RawFormat)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Haresh Chaudhari
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionSee instead Pin
Nathanael Jones6-Jan-12 7:37
memberNathanael Jones6-Jan-12 7:37 
GeneralMy vote of 1 Pin
aa.azizkhani25-Nov-08 20:45
memberaa.azizkhani25-Nov-08 20:45 
GeneralMy vote of 1 Pin
James Luterek25-Nov-08 6:23
memberJames Luterek25-Nov-08 6:23 
GeneralMy vote of 1 Pin
Ramon Smits25-Nov-08 5:04
memberRamon Smits25-Nov-08 5:04 
GeneralCaching Pin
Ramon Smits25-Nov-08 5:03
memberRamon Smits25-Nov-08 5:03 
GeneralBad code Pin
Ramon Smits25-Nov-08 5:02
memberRamon Smits25-Nov-08 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 25 Nov 2008
Article Copyright 2008 by Haresh Chaudhari
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid