问题:
我几天前在这里发现了这个功能,但我再也找不到了。它调整图像大小,但输出质量不好。看起来颜色深度是8位。
第一张照片是原始照片,第二张照片是Photoshop,最后一张是通过代码调整大小:
样品:
功能:
Image ResizeImage(Image original, int targetWidth)
{
double percent = (double)original.Width / targetWidth;
int destWidth = (int)(original.Width / percent);
int destHeight = (int)(original.Height / percent);
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
try
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.DrawImage(original, 0, 0, destWidth, destHeight);
}
finally
{
g.Dispose();
}
return (Image)b;
}