문제

I'm trying to use DrawingContext.DrawGeometry get a rectangle with 1 device pixel wide sides.

var geometry = (defined elsewhere from a Rect {0.0, 0.0, 8.0, 18.0})
var brush = new SolidColorBrush(Color.FromArgb(30, 0xff, 0xff, 0xff));

// Note: the pen is declared with a 1.0 thickness
var pen = new Pen(new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF)), 1.0)

drawingContext.DrawGeometry(brush, pen, geometry);

I have verified that the Rect I'm building the geometry with is whole numbers, not fractional points (manually verified), and the Pen I'm drawing the geometry with is 1.0 units wide.

The problem is that the rect is being drawn on screen 2 device pixels wide. How can I draw this rectangle on exact device pixels? I'm expecting that at 96dpi, this will come out to 1 pixel.

도움이 되었습니까?

해결책

You can use DrawingContext.PushGuidelineSet to force the rendering to align when possible.

For details and sample code, see this tutorial.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top