This project is read-only.

DrawLine changes x and y coordinates when a point is outside the bounds in stead of clipping it

Feb 7, 2011 at 9:44 PM


I'm having problems with the DrawLine method.

Eg. I call DrawLine with x1 and y1 being a point inside the WriteableBitmap and x2 and y2 being a point outside. I would expect that the line to be drawn would be clipped at the point where it intersects with the boundary of the WriteableBitmap. In stead it seems that x2 is set to 0 if it is below 0 and to the width of the WriteableBitmap if it is above the width of the WriteableBitmap. The same goes for y2 but with the height of the WriteableBitmap as the max value.

This behavior is very apparent in the following example:

bmp.DrawLine(0, -100, 400, -20, Colors.Red);

This is a line that is outside the WriteableBitmap and I wouldn't expect it to draw anything on the bmp. None the less that's what it does. A red line is drawn from (0, 0) to (400, 0) because y1 and y2 are set to 0 when they are below 0.

I guess this is by design, but wouldn't it make more sense to clip it?

I've tried to calculate the intersection and change the endpoint of my line to the intersection point, but this is too slow for my application. Well my intersection code is slow, but it could probably be done faster.

Feb 7, 2011 at 9:55 PM


Have you used the latest version from the source code or the binary? The binary is quite old and I hope to build a new binary version soon.


- Rene Schulte

Feb 7, 2011 at 10:11 PM
Edited Feb 7, 2011 at 10:12 PM

I was using the binary. With the latest source code it works like a charm.

Thanks the help and thanks for a great library!

Feb 7, 2011 at 10:16 PM

Maybe I should start a new discussion... But just a quick question here. Do you plan to extend the library with thick line drawing capabilities? Like this:

Feb 8, 2011 at 9:43 AM
Edited Feb 8, 2011 at 9:43 AM

I plan to add this in a later version. I already created a work item a while ago: