如何在保存文件夹时调整图像大小 [英] how to resize an image whileing saving in an folder

查看:125
本文介绍了如何在保存文件夹时调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个(600 * 800大小)或任何大小的图像文件。现在我需要将它们转换为尺寸为****(110 * 110)****

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)****

的thubnail图像尺寸,但如果我减小尺寸一个图像我不应该改变图像的质量。一旦我们缩小图像尺寸,图像质量就会消失

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

有没有影响图像质量的方法我们可以将它们转换为缩略图[在.net中有没有内置类。

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)

任何帮助都会很棒

推荐答案

那么,关于如何做,有一个有趣的材料这里可以帮助你。

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.

这是从链接获得的代码,老实说,我认为从Bitmap开始的最后5行代码b = new Bitmap(destWidth,destHeight);足以解决您的问题。

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;
}

这篇关于如何在保存文件夹时调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆