I am creating thumbnail of Image file but it gives very poor quality image. please suggest me the way to improve the quality of thumbnail. my function is given below-
public Image RezizeI(Image img, int maxW, int maxH)
{
if (img.Height < maxH && img.Width < maxW) return img;
using (img)
{
Double xRatio = (double)img.Width / maxW;
Double yRatio = (double)img.Height / maxH;
Double ratio = Math.Max(xRatio, yRatio);
int nnx = (int)Math.Floor(img.Width / ratio);
int nny = (int)Math.Floor(img.Height / ratio);
Bitmap cpy = new Bitmap(nnx, nny, PixelFormat.Format32bppArgb);
using (Graphics gr = Graphics.FromImage(cpy))
{
gr.Clear(Color.Transparent);
// This is said to give best quality when resizing images
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.DrawImage(img,
new Rectangle(0, 0, nnx, nny),
new Rectangle(0, 0, img.Width, img.Height),
GraphicsUnit.Pixel);
}
return cpy;
}
}
for example my original image is
and created thumbnail is-