我使用此代码来调整图像大小。但结果不好,我想要最好的质量。我知道它的低质量,因为我也调整了与photoshop相同的图像,结果是不同的更好。我如何解决它?调整图像大小时出现质量问题?
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;
}
我知道它只是调整大小,但它值得说你正在比较一个JavaScript功能1000美元的专业图形软件。所以它有可能得到不同的结果。 – Iznogood 2010-08-27 13:02:49
其不是javascript函数它的c#,我知道有一种方法可以用c# – beratuslu 2010-08-27 13:25:41
[ImageResizing.Net](http://imageresizing.net)库会给你最好的质量,并处理[29+图像调整大小陷阱](http://nathanaeljones.com/163/20-image-resizing-pitfalls/)。看看后面的链接,以获得提高质量的提示 - 如果您希望免费的开放源代码解决方案为您处理所有边缘案例,请查看前者。 – 2011-08-02 23:15:20