Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET Windows Application , +
I once again one question about image upload.
I want to resize the image before saving at other loadtion.
For example i have selected "D:\MemberImage\MyPhoto.jpg" with size 500px*350px.
Now before saving this file at other location i want to resize this selected file to 160px*120px and then save this resized image in new location.
I mean when i save my file
my new.jpg file should be of size 160px*120px;
Please help me some
Thanks and regards.
Posted 18-Sep-11 21:57pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

Try this for resizing and save to a new location
string strPath = @"D:\MemberImage\MyPhoto.jpg";
            System.Drawing.Image img = System.Drawing.Image.FromFile(strPath);
            img=Resize(img, 160, 120);
//resize image 
private Image Resize(Image img, int iWidth, int iHeight)
            Bitmap bmp = new Bitmap(iWidth, iHeight);
            Graphics graphic = Graphics.FromImage((Image)bmp);
            graphic.DrawImage(img, 0, 0, iWidth, iHeight);
            return (Image)bmp;
suman161288 at 19-Sep-11 15:54pm
It works.
Thanks a lot.
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

try the following :
string directory = AppDomain.CurrentDomain.BaseDirectory + "PhotoGallery/Slides/";
                        Bitmap originalBMP = new Bitmap(fuphotos.FileContent);
                        int origWidth = originalBMP.Width;
                        int origHeight = originalBMP.Height;
                        int sngRatio = origWidth / origHeight;
                        int newWidth = 213;
                        int newHeight = 200;
                        Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
                        Graphics oGraphics = Graphics.FromImage(newBMP);
                        oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
                        newBMP.Save(directory + cfilename);
                        strcFilepath = @"~/PhotoGallery/Slides/" + cfilename;
Rate this: bad
Please Sign up or sign in to vote.

Solution 7

Why, with extension methods, of course:
public static class ExtendBitmap
    public static Bitmap Resize(this Bitmap bmp, int nWidth, int nHeight )
        Bitmap result = new Bitmap(nWidth, nHeight);
        using(Graphics g = Graphics.FromImage((Image)result))
            g.DrawImage(bmp, 0, 0, nWidth, nHeight);
        return result;
    public static Bitmap Resize(this Bitmap bmp, double percent)
        int width = (int)(bmp.Width * (percent*0.01));
        int height = (int)(bmp.Height * (percent*0.01));
        Bitmap result = bmp.Resize(width, height);
        return result;
Load the bitmapo the way you normally would, and then do this:
Bitmap bmp = Bitmap.FromFile("blah blah");
bmp = bmp.Resize(50);
// or 

bmp = bmp.Resize(320, 240);
nsaxena at 21-Dec-12 5:59am
Whatever you do. You are going to loose transparency, it will be replaced with black color.
Any solution for bitmaps ?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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

  Print Answers RSS
0 OriginalGriff 476
1 Sergey Alexandrovich Kryukov 215
2 CHill60 195
3 Afzaal Ahmad Zeeshan 145
4 TheRealSteveJudge 120
0 Sergey Alexandrovich Kryukov 9,061
1 OriginalGriff 7,920
2 Peter Leow 4,774
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,176

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100