【发布时间】:2011-08-08 19:38:12
【问题描述】:
我正在使用 .NET 4 中的以下 WPF 代码在控制台应用程序中调整 PNG 的大小:
const int width = 250;
const int height = 179;
DrawingGroup group = new DrawingGroup();
RenderOptions.SetBitmapScalingMode(group, BitmapScalingMode.Fant);
group.Children.Add(new ImageDrawing(source, new Rect(0, 0, width, height)));
DrawingVisual targetVisual = new DrawingVisual();
using (DrawingContext targetContext = targetVisual.RenderOpen())
{
targetContext.DrawDrawing(group);
targetContext.Close();
RenderTargetBitmap target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);
target.Render(targetVisual);
BitmapSource resized = BitmapFrame.Create(target);
}
在 Windows 7 上运行时,这完全符合预期,但在 Windows Server 2003 上运行时,我得到了我认为的抗锯齿伪影。
This Image 显示当在具有白色背景的网页上显示时,Server 2003 图像如何在不应存在的白色区域中出现额外的水平和垂直灰线。
放大一小部分以尝试找出正在发生的事情this image 显示了原始 PNG 如何在透明部分(显示为灰色和白色方格)和白色区域之间有一条 1 像素的半透明线。两张调整大小的图像都有相同的半透明线,但在 Server 2003 下的那张在透明度级别上有一些奇怪的变化。
有一个很好的 MSDN 文档关于在 WPF (http://msdn.microsoft.com/en-us/library/aa970908.aspx) 中调整图像大小时抗锯齿的效果,这似乎与我的症状相匹配我在这里看到,但为什么这在 Windows 7 和 Server 2003 之间会有所不同??
我试图找到切换抗锯齿的方法来使用以下代码测试这个理论,但没有任何区别:
RenderOptions.SetEdgeMode(group, EdgeMode.Aliased);
【问题讨论】:
标签: c# .net wpf image-processing png