.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Image Resize

Posted By: Akhil Raj     Posted Date: September 20, 2008    Points:2   Category :ASP.Net
hi friends,
I am using file upload control for uploading images. But when i am displaying in the details vies i want it in the thumbnail size. I got some idea that is saving the image with resized when uploading. Can anyone help me how can i achieve easily.
1. Now i uploaded the image in to server.
2. Save as with new size
3. delete the old one
I think now u got. i want directly save with new size or replace the old one.

Author: Amit Mehra             
Posted Date: September 20, 2008     Points: 5   

You can use below code to resize image.

public static Bitmap CreateThumbnail(string lcFilename,int lnWidth, int lnHeight)

System.Drawing.Bitmap bmpOut = null;
Bitmap loBMP = new Bitmap(lcFilename);

ImageFormat loFormat = loBMP.RawFormat;

decimal lnRatio;

int lnNewWidth = 0;

int lnNewHeight = 0;

//*** If the image is smaller than a thumbnail just return it

if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)

return loBMP;

if (loBMP.Width > loBMP.Height)
lnRatio = (decimal) lnWidth / loBMP.Width;

lnNewWidth = lnWidth;

decimal lnTemp = loBMP.Height * lnRatio;

lnNewHeight = (int)lnTemp;
lnRatio = (decimal) lnHeight / loBMP.Height;

lnNewHeight = lnHeight;

decimal lnTemp = loBMP.Width * lnRatio;

lnNewWidth = (int) lnTemp;

bmpOut = new Bitmap(lnNewWidth, lnNewHeight);

Graphics g = Graphics.FromImage(bmpOut);

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

g.FillRectangle( Brushes.White,0,0,lnNewWidth,lnNewHeight);



return null;

return bmpOut;


other way you can also set the Height/width of the Image control, the control will automatically shrink the image while displaing , in this case you dont have resize the image.

Please "Mark As Answer " if this post help you.
Author: Akhil Raj       [Moderator]      
Posted Date: September 20, 2008     Points: 5   

hi friend,
I will try the first method.
The second method u told in the Image control just specify the width and height. I already tried this and failed so only come to resize.

Author: marrisa             
Posted Date: July 01, 2013     Points: 20   

for me, i'd like to choose the second one.
with right code, it is easy to realize image resize, and you can see relevant code on this page http://www.rasteredge.com/how-to/vb-net-imaging/resize-image/.

Author: arronlee             
Posted Date: July 13, 2015     Points: 20   

How about changing the image size by using some 3rd party toolkits?
Like: http://www.pqscan.com/convert-pdf/to-image-size-csharp.html

Next Tomorrow is Another Day .

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend