c#image使用新位图vs绘制图像调整大小 [英] c# image resize with new bitmap vs draw image
问题描述
有什么区别?
位图newImage =新位图(_ currentBitmap,newWidth,newHeight);
返回newImag;
AND
位图animage =新位图(newWidth,newHeight);
使用(Graphics gr = Graphics.FromImage(animage))
{
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.InterpolationMode = InterpolationMode .HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.CompositingQuality = CompositingQuality.HighQuality;
gr.DrawImage(_ currentBitmap,new Rectangle(0,0,newWidth,newHeight));
}
返回animage;
what is the difference?
Bitmap newImage = new Bitmap(_currentBitmap, newWidth, newHeight);
return newImag;
AND
Bitmap animage= new Bitmap( newWidth, newHeight);
using (Graphics gr = Graphics.FromImage(animage))
{
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.CompositingQuality = CompositingQuality.HighQuality;
gr.DrawImage(_currentBitmap, new Rectangle(0, 0, newWidth, newHeight));
}
return animage;
推荐答案
几乎没有,这是.NET框架中System.Drawing.Bitmap(Image,int,int)的源代码:
Almost nothing, here is the source code of the System.Drawing.Bitmap(Image, int, int) in the .NET framework:
public Bitmap(Image original, int width, int height) : this(width, height) {
Graphics g = null;
try {
g = Graphics.FromImage(this);
g.Clear(Color.Transparent);
g.DrawImage(original, 0, 0, width, height);
}
finally {
if (g != null) {
g.Dispose();
}
}
}
查看文档: http://msdn.microsoft.com/en-us/library/334ey5b7.aspx [ ^ ]。
当你可以看到,这个构造函数的文档没有指定图像是如何缩放的,这是什么插值质量。在第二个代码示例中,您可以指定它。您可以使用第二个代码示例并确定如何完成缩放(因为您可以逐个像素地比较最终结果)。但是,您不能依赖这些结果:因为文档中没有描述此细节,结果可能取决于某些未知因素,例如.NET框架的版本。一旦图像质量很重要,我总是会使用代码的第二个变体。
-SA
这篇关于c#image使用新位图vs绘制图像调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!