Sometimes, scaling down a bitmap generates a bigger file. Why?
- by Matías
Hello,
I'm trying to write a method to reduce the size of any image 50% each time is called but I've found a problem. Sometimes, I end up with a bigger filesize while the image is really just half of what it was. I'm taking care of DPI and PixelFormat. What else am I missing?
Thank you for your time.
public Bitmap ResizeBitmap(Bitmap origBitmap, int nWidth, int nHeight)
{
Bitmap newBitmap = new Bitmap(nWidth, nHeight, origBitmap.PixelFormat);
newBitmap.SetResolution(origBitmap.HorizontalResolution, origBitmap.VerticalResolution);
using (Graphics g = Graphics.FromImage((Image)newBitmap))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(origBitmap, 0, 0, nWidth, nHeight);
}
return newBitmap;
}