Click here to Skip to main content
15,908,581 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to reduce the image of size using, without lose of image quality

Bitmap was just saved with a smaller resolution with a '.jpg' slapped onto it, and not compressed accordingly. The following code now works.

Bitmap tempBmp = new Bitmap(filePath);
Bitmap bmp = new Bitmap(tempBmp, 807, 605);

@"C:\NewPicFolder\Pic" + count + ".jpg",

See one more solution on the following link

C#: Image resize, convert, and save
Share this answer
Here is a simple program to help you to reduce the size of image in pixel.
Please give it a look
Share this answer
Found this method on one of the threads of CodeProject[^]
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);

You might be interested in this as well :[^][^][^][^]

Share this answer
protected void btnsave_Click(object sender, EventArgs e)
string filename = Path.GetFileName(fileupload1.PostedFile.FileName);
string targetPath = Server.MapPath("Images/" + filename);
Stream strm = fileupload1.PostedFile.InputStream;
var targetFile = targetPath;
//Based on scalefactor image size will vary
GenerateThumbnails(0.5, strm, targetFile);

private void GenerateThumbnails(double scaleFactor, Stream sourcePath, string targetPath)
using (var image = Image.FromStream(sourcePath))
var newWidth = (int)(image.Width * scaleFactor);
var newHeight = (int)(image.Height * scaleFactor);
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbnailImg.Save(targetPath, image.RawFormat);

Also see below link[^]
Share this answer
If the image has reasonable quality and compressed reasonably well, you cannot keep its quality if you reduce the size. Note, that you did not really explain what do you mean by size: size in pixels or size of image file in bytes. In both meaning, the problem is pretty much hopeless. Well, if you are talking about size of file, and the file was not compressed or poorly compressed, you usually can compress it better and hence keep subjective quality reasonably well.

As the question is not certain enough, I cannot provide more detail, but my past answers could help you:
resize image in[^],
Read Big Tiff and JPEG files (>(23000 x 23000) pix) in a stream. And display part of it to the screen in realtime.[^].

Share this answer
Here's a tip, create a

for your image and for example you want your image size to be 20px x 20px
then set your div size to that.

Then use photoshop to resize the image.
Share this answer

I'll go with the code which was given by Krinal Rohit. But be adviced that some PNG images cannot be re-sized with convesional methods described above. Though it good for beginners to learn the basics of drawing using Asp.Net namespaces like System.Drawing and System.Drawing.Imaging.

There are online tools like and Online Image Re-sizer with which you can get the desired result. can reduce the size of a PNG image drastically.

Share this answer

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