Reputation: 2596
I am trying to increase the size of an uploaded image using system.drawing
. It works but the file sizes are much larger than if I were to do this using Photoshop. Is this something I will have to cope with or is there a way to decrease the file size?
I am using this code, and have tweaked the Drawing2d settings but it doesn't make an appreciable difference.
resizedImage = New Bitmap(newWidth, newHeight, image.PixelFormat)
graphics = graphics.FromImage(resizedImage)
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality
graphics.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
graphics.FillRectangle(Brushes.White, 0, 0, newWidth, newHeight)
graphics.DrawImage(image, 0, 0, newWidth, newHeight)
Do I need to use a dedicated library for this to achieve better results?
Upvotes: 0
Views: 164
Reputation: 66641
The parameters you have here are affect the "rendering" of the image, not the "image file size".
To affect the image file size, you need to drop down the quality of the jpeg when you save it, using the Image.Save Method
This is a snipped code from the MSDN Example on how you can drop down the image file size.
// Save the bitmap as a JPEG file with quality level 25.
myEncoderParameter = new EncoderParameter(myEncoder, 25L);
myEncoderParameters.Param[0] = myEncoderParameter;
// and now save it to the file
myBitmap.Save("Shapes025.jpg", myImageCodecInfo, myEncoderParameters);
Upvotes: 2