0

我正在尝试将 WPF 中的多个图像渲染到画布上。在下面的人为示例中,我能够使用以下代码重现意外行为:

public class MyCanvas : Canvas
{
    protect override void OnRender(DrawingContext drawingContext)
    {
        base.OnRender(drawingContext);
        BitmapSource image = BitmapSource.Create(1, 1, 96, 96, PixelFormats.Indexed8, BitmapPalettes.Gray256, new byte[] { 0 }, 2);
        drawingContext.DrawImage(image, new Rect(10, 10, 128, 128));
        drawingContext.DrawImage(image, new Rect(10, 138, 128, 128));
    }
}

这将产生以下绘图: 用细线绘图。如您所见,在两个矩形之间有一条细(可能是一个像素)宽的线。我期待一个绘图,两个矩形都接触。

所以我的问题是: 为什么 WPF 不将图像渲染为感人?

4

0 回答 0