This project is read-only.

FillRectangle bug?

Nov 20, 2012 at 12:51 PM
Edited Nov 20, 2012 at 6:07 PM

Hi. I'm run this code :

writeableBmp.FillRectangle(0, 0, 2, 2, Colors.Red);

But, in result, rendered rectangle 2x3. If i replace '<=' by '<' in code:

for(var y = startYPlusX1 + w; y <= offset2; y += w)

(source: WriteableBitmapFillExtensions.cs->FillRectangle(...)), when all ok.

It's bug or not?

Nov 27, 2012 at 9:24 AM

If you look at the API documentation, the "2, 2" in your call does not represent the width and height of the rectangle, but the end coordinate:


/// <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>
/// <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>

I agree that the code is wrong, but (at least in my opinion) the size of the rectangle should be 3 x 3. I would interpret the right-bottom coordinate to be included in the rectangle fill, but I realize that other interpretations are possible. To avoid further confusion it would be good if the API documentation would explicitly state whether end coordinates are included or not in fills etc.

I have recently posted an issue report on the FillRectangle inconsistency and a similar problem in FillPolygon, please have a look here.

Jan 3, 2013 at 5:16 PM
Edited Jan 3, 2013 at 5:20 PM

Sorry for the trouble. You're right the method was wrong, also DrawRectangle. It's fixed in the latest source code and the end coordinates are now always included. So 0, 0, 2 ,2 will draw a 3 x 3 rectangle.


- Rene