0

i have an image file which is of (600* 800 size) or any size . now i need to convert them into an thubnail image size which is of size ****(110*110)****

but if i reduce the size of an image i should not change the Quality of image. as once we reduce an image size the the Quality of the image is gone

is there any way without affecting the Quality of the image we can convert them into an thumbnail image[ is there any built in class for that in .net)

any help would be great

Andres
  • 3,324
  • 6
  • 27
  • 32
happysmile
  • 7,537
  • 36
  • 105
  • 181

2 Answers2

3

Well, about how to do it, there's a interesting material here the may help you.

About losing quality, if you mean resolution, there's no way as long as you are downsizing an image, you are throwing away spacial information that no longer can be rebuilt. Of course if you use some sort of interpolation, but it will never be the same as your original picture.

What you can do is store one version of each.

Here's the code got from the link and honestly, I think that the last 5 lines of code starting at Bitmap b = new Bitmap(destWidth, destHeight); is enough to solve your problem.

private static Image resizeImage(Image imgToResize, Size size)
{
   int sourceWidth = imgToResize.Width;
   int sourceHeight = imgToResize.Height;

   float nPercent = 0;
   float nPercentW = 0;
   float nPercentH = 0;

   nPercentW = ((float)size.Width / (float)sourceWidth);
   nPercentH = ((float)size.Height / (float)sourceHeight);

   if (nPercentH < nPercentW)
      nPercent = nPercentH;
   else
      nPercent = nPercentW;

   int destWidth = (int)(sourceWidth * nPercent);
   int destHeight = (int)(sourceHeight * nPercent);

   Bitmap b = new Bitmap(destWidth, destHeight);
   Graphics g = Graphics.FromImage((Image)b);
   g.InterpolationMode = InterpolationMode.HighQualityBicubic;

   g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
   g.Dispose();

   return (Image)b;
}
Andres
  • 3,324
  • 6
  • 27
  • 32
0

when you downsize an image you do not reduce it's quality, only when you try to bring it back to it's original size from the downsized version the quality will be affected.

GxG
  • 4,491
  • 2
  • 20
  • 18