Click here to Skip to main content
16,019,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
coding for how to resize image in asp.net
Posted

Hi @Abhinav

please use the following code
C#
// Calculate the new image dimensions
            System.Drawing.Bitmap originalBMP = new System.Drawing.Bitmap(FileUploadCtrlPatientPhoto.FileContent);

            int origWidth = originalBMP.Width;
            int origHeight = originalBMP.Height;
            int sngRatio = origWidth / origHeight;
            int newWidth = 100;

            if (sngRatio == 0)
                sngRatio = 1;

            int newHeight = newWidth / sngRatio;

            // Create a new bitmap which will hold the previous resized bitmap
            System.Drawing.Bitmap newBMP = new System.Drawing.Bitmap(originalBMP, newWidth, newHeight);                // Create a graphic based on the new bitmap
            System.Drawing.Graphics oGraphics = System.Drawing.Graphics.FromImage(newBMP);

            // Set the properties for the new graphic file
            oGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 
            oGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;   
             // Draw the new graphic based on the resized bitmap
            oGraphics.DrawImage(originalBMP, 0, 0, 120, 130);

            // Save the new graphic file to the server
            newBMP.Save(UploadPath);//upload path is either set from the webconfig file or some where else

            // Once finished with the bitmap objects, we deallocate them.
            originalBMP.Dispose();
            newBMP.Dispose();
            oGraphics.Dispose();    

Hope this will help you

Thanks
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900