调整小尺寸System.Drawing.Bitmap的大小可以完全降低质量 [英] Complete Quality loss in resizing the small sized System.Drawing.Bitmap

查看:381
本文介绍了调整小尺寸System.Drawing.Bitmap的大小可以完全降低质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨全部,

 

我在调整较小尺寸的System.Drawing.Bitmap 时面临完全
质量损失。我使用的是大小为8 X 8(以像素为单位)的位图。

 

当我将其调整为1 X 1时,图像内容为
完全空白

 

我怀疑这是尺寸问题,所以我再次获得
调整结果图像的大小(1 X 1) 到8 X 8.输出图像再次为空白。它说明了在调整位图大小时发生完全质量损失。

I had suspected that this to be size problem, So I have again resized the resultant image(1 X 1) to 8 X 8. The output Image is again blank. It illustrates that the complete quality loss occurred in resizing the Bitmaps.

 

能不能让我知道这是一个已知问题还是任何解决方案都有待克服这个问题?

 

请查看我所遵循的复制步骤以及下面的代码段。

 

Bitmap originalImage; Bitmap resizedImage_1; Bitmap resizedImage_2;

 

步骤1:将原始图像保存到磁盘(用于检查访问丢失和将其保存到本地光盘) - 没有损失
发生

Step 1: Saving the original image to disk (for testing purpose to check loss in accessing and saving it to local disc) - No loss occurred

 

originalImage =(Bitmap)Image.FromFile(" ../../ Images / Tiling image.bmp",true); // Size:8 x 8 in pixel originalImage.Save(" original.bmp");

 

步骤2:将图像大小调整为1 X 1 - 发生损失

Step 2: Resizing image to 1 X 1 - Loss Occurred

 

resizedImage_1 = new Bitmap(1,1); Graphics formGraphics = System.Drawing.Graphics.FromImage(resizedImage_1); formGraphics.DrawImage(originalImage,new Rectangle(0,
0,1, 1)); resizedImage_1.Save(" Resized_1.bmp"); formGraphics.Dispose();

 

步骤3:将步骤1中的结果图像调整为8×8 - 发生损失

Step 3: Resizing the resultant image from Step 1 to 8 X 8 - Loss Occurred

resizedImage_2 = new Bitmap(8,8); Graphics formGraphics = System.Drawing.Graphics.FromImage(resizedImage_2); formGraphics.DrawImage(resizedImage_1,new
RectangleF(0,0,1, 1)); resizedImage_2.Save(" Resized_2.bmp"); formGraphics.Dispose();

 

我们非常感谢您的建议。

 

谢谢,

推荐答案

调整大小时,特别是调整大小为1像素时,使用InterpolationMode的适当设置和Graphics对象的PixelOffsetMode来"保持"图像中的颜色。

when resizing, especially resizing down to 1 pixel use an appropriate setting of the InterpolationMode and the PixelOffsetMode of the Graphics object to "keep" the color in the image.

您需要导入Drawing2d:

you need to import Drawing2d:

使用System.Drawing.Drawing2D;

using System.Drawing.Drawing2D;

formGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
formGraphics.PixelOffsetMode = PixelOffsetMode.Half;
formGraphics.DrawImage(...); //...

问候,

  Thorsten

  Thorsten


这篇关于调整小尺寸System.Drawing.Bitmap的大小可以完全降低质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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