我正在创建图像文件的缩略图,但它会提供质量非常差的图像。请建议我提高缩略图质量的方法。我的功能如下 -
public Image RezizeI(Image img, int maxW, int maxH)
{
if (img.Height < maxH && img.Width < maxW) return img;
using (img)
{
Double xRatio = (double)img.Width / maxW;
Double yRatio = (double)img.Height / maxH;
Double ratio = Math.Max(xRatio, yRatio);
int nnx = (int)Math.Floor(img.Width / ratio);
int nny = (int)Math.Floor(img.Height / ratio);
Bitmap cpy = new Bitmap(nnx, nny, PixelFormat.Format32bppArgb);
using (Graphics gr = Graphics.FromImage(cpy))
{
gr.Clear(Color.Transparent);
// This is said to give best quality when resizing images
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.DrawImage(img,
new Rectangle(0, 0, nnx, nny),
new Rectangle(0, 0, img.Width, img.Height),
GraphicsUnit.Pixel);
}
return cpy;
}
}
例如我的原始图片是
并创建了缩略图 -
答案 0 :(得分:0)
我不能保证,但我过去用来创建质量更好的缩略图的代码包括这两行......
gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality;
gr.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality;