This project is read-only.


FillRectangle incorrectly includes right/bottom


If you call FillRectangle and pass a rectangle with width 1 and height 1, it instead fills an area 2 pixels wide and 2 pixels high.

It appears that WriteableBitmapEx's FillRectangle is including x2 and y2 in its rectangle. This is inconsistent with both System.Drawing and WPF, as well as every other graphics library I've ever used (GDI, GDI+, Delphi's TCanvas, ImageMagick, PyGame, etc.) FillRect calls typically do not fill the right-most column or the bottom-most row. That's because rectangle coordinates typically represent the grid lines between pixels, and that's because the math is far, far easier that way. (Raymond Chen has a good explanation at

Repro (using the latest NuGet release,
var bitmap = BitmapFactory.New(2, 2);
// Should fill an area (1 - 0) pixels wide and (1 - 0) pixels high
bitmap.FillRectangle(0, 0, 1, 1, Colors.Red);
MyImage.Source = bitmap;
Expected: a 2x2 bitmap with one red pixel in the top left.

Actual: a 2x2 bitmap completely filled with red.


JeroenWalter wrote Oct 28, 2015 at 1:48 PM

This is solved incorrectly.

As it is now it is never possible to fill the right side or the bottom side of the bitmap.

It would be better to change the parameters of FillRectangle from x1,y1,x2,y2 to x,y,width,height.