C# 创建缩略图会产生非常差的图像质量
我正在创建图像文件的缩略图,但它提供的图像质量非常差。请告诉我如何提高缩略图的质量。下面给出了我的函数-C# 创建缩略图会产生非常差的图像质量,c#,asp.net,image,C#,Asp.net,Image,我正在创建图像文件的缩略图,但它提供的图像质量非常差。请告诉我如何提高缩略图的质量。下面给出了我的函数- public Image RezizeI(Image img, int maxW, int maxH) { if (img.Height < maxH && img.Width < maxW) return img; using (img) { Double xRatio = (do
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;
}
}
public Image RezizeI(图像img、int-maxW、int-maxH)
{
if(img.Height
例如,我的原始图像是
所创建的缩略图是——
我不能保证,但我过去用来创建质量更好的缩略图的代码包括以下两行
gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality;
gr.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality;
你说的质量差是指W:H比率的变化吗?不,这不是问题所在。问题在于质量,即图像看起来像是由小点组成的。我不知道它到底叫什么,可能是像素。正如您在拇指图像中看到的。没有出现相同的问题。首先,看起来缩略图的比例不同。第二,在缩小图像大小时,期望图像质量较低。缩略图就是它是什么,缩略图。您应该在较小的屏幕区域上显示缩略图,这样图像质量的降低就不会有任何关系。请尝试在您从中获取代码的同一问题上复制缩略图时使用的其他属性。。。