调整位图大小后,新位图的结果是平滑bitmnap

Yan*_*hof 1 c#

我使用简单的重新大小方法将我的位图更改为新的大小.原始位图大小为320x240,我将大小改为两次

  • 至250x160
  • 在位图上做一些处理
  • 将其更改回320x240

我发现在将其更改回320x240之后,我发现位图很平滑,而不是我除外.

我怎样才能避免这种顺利出现?

Resize方法:

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;
}
Run Code Online (Sandbox Code Playgroud)

Fal*_*nwe 5

可悲的是你做不到.当您将位图的大小调整为较小的大小时,信息将丢失.并且从小图像(具有较少信息)内插信息以创建具有原始尺寸的新的红外图像.正是这种插值使得到的图像具有平滑的外观.

为避免这种情况,您唯一能做的就是找到一种方法来进行必要的处理,而无需在整个过程中调整图像大小.