Click here to Skip to main content
14,391,240 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear Sir,

How to reduce image size in with same clarity

I am uploading image using file upload control.

its size Example:
My Image Size is => 1 MB to 3MB.
it will reduce below 100 KB size.

it will display same clarity what image original size is.

Please tell me how to make a code for reduce image size???

Rate this:
Please Sign up or sign in to vote.

Solution 2

Use following function to reduce image size. It will regenerate image with defined height and width.

public static void ResizeImage(string image, string Okey, string key, int width, int height, string newimagename)
        System.Drawing.Image oImg = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image));

        System.Drawing.Image oThumbNail = new System.Drawing.Bitmap(width, height);//, System.Drawing.Imaging.PixelFormat.Format24bppRgb

        System.Drawing.Graphics oGraphic = System.Drawing.Graphics.FromImage(oThumbNail);

        oGraphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

        //set smoothing mode to high quality
        oGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        //set the interpolation mode
        oGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        //set the offset mode
        oGraphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

        System.Drawing.Rectangle oRectangle = new System.Drawing.Rectangle(0, 0, width, height);

        oGraphic.DrawImage(oImg, oRectangle);

        if (newimagename == "")
            if (image.Substring(image.LastIndexOf(".")) != ".png")
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image), System.Drawing.Imaging.ImageFormat.Jpeg);
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image), System.Drawing.Imaging.ImageFormat.Png);
            if (newimagename.Substring(newimagename.LastIndexOf(".")) != ".png")
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + newimagename), System.Drawing.Imaging.ImageFormat.Jpeg);
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + newimagename), System.Drawing.Imaging.ImageFormat.Png);
Member 9534579 23-Oct-13 3:52am
What we use in place of HttpContext?
Member 9534579 23-Oct-13 3:56am
What parameters we need to pass when we call this method to another method for imgae saving?
Mukund Thakker 23-Oct-13 5:43am
int iMinAircraftImgWidth = 500;
int iMinAircraftImgHeight = 372;
ResizeImage(imagename, "imagepath", "imagepath", iMinAircraftImgWidth, iMinAircraftImgHeight, strNewFileName);
Member 9534579 23-Oct-13 7:33am
Member 10752740 16-Apr-14 3:59am
i want only reduce image file size
Rate this:
Please Sign up or sign in to vote.

Solution 1

Use following code to reduce size without loss of clarity
Image img;
Mohankumar.Engain 9-Apr-12 5:27am
My image sizes, I declared Only 100px * 100px.
Then how to make it reply me.
Muralikrishna8811 9-Apr-12 5:29am
then replace 400 with 100
by default it takes as pixels
Rate this:
Please Sign up or sign in to vote.

Solution 3

A very simple way to decrease size of an image or generating a thumbnail

check this out

Creating Thumbnail Image by keeping Aspect Ratio using C#
Rate this:
Please Sign up or sign in to vote.

Solution 4


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

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