WPF Drawing images leaves unexpected empty line of pixels

85 Views Asked by At

I'm trying to render multiple images in WPF onto a canvas. In the following contrived example, I was able to reproduce the unexpected behavior using following code:

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));
    }
}

This results in the following drawing: Drawing with thin line. As you can see, there is thin (probably one pixel) wide line,between the two rectangles. I expected a drawing, where both rectangles touch.

So my question is: Why doesn't WPF render the images as touching?

0

There are 0 best solutions below