我使用简单的重新大小方法将我的位图更改为新大小。 原始位图大小为320x240,我将大小改为两次
我发现在将其更改回320x240之后,我发现位图很平滑,而不是我除外。
我怎样才能避免这种顺利出现?
调整大小方法:
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;
}
答案 0 :(得分:5)
为了避免这种情况,您唯一能做的就是找到一种方法来进行必要的处理,而无需在处理过程中调整图像大小。
答案 1 :(得分:2)
由于您正在使用HighQualityBicubic插值模式,因此将使用最高质量对图像进行预滤波和调整大小,从而产生“平滑效果”。
您可以尝试将InterpolationMode属性设置为NearestNeighbor
以获得“更粗糙”的结果:
Bitmap b = new Bitmap(destWidth, destHeight);
using (Graphics g = Graphics.FromImage((Image) b)) {
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
}