Rectangle odd behavior
Tech-Archive recommends: Fix windows errors by optimizing your registry
- From: <Rene>
- Date: Wed, 5 Oct 2005 12:25:28 -0500
I am having a hard time understanding the logic behind the Rectangle object.
My problem has to do with the way the rectangle treats the "Width" property.
For example, take the following rectangle object.
Rectangle myRec = new Rectangle(0, 0, 2, 2);
If you draw this rectangle on the screen you will end up with a rectangle
like the one shown below (The character "X" represents a pixel used to draw
the rectangle and the character "O" is an untouched pixel):
XXX
XOX
XXX
Take a close look at that rectangle. I in my head, this rectangle is not 2
pixels width, for me, this rectangle is actually 3 pixels width. So here is
my first question. Do you agree with me that this rectangle is really 3
pixels with and not 2?
Things get more confusing when you try to draw something inside the
rectangle using a function such as DrawIcon() or FillRectangle(). For
example if you use the FillRectangle() function and pass it the rectangle
object created above the program will draw the following filled rectangle
(The character "X" represents a pixel used to draw the filled rectangle and
the character "O" is an untouched pixel):
XXO
XXO
OOO
Although my rectangle was 3 pixels width, the function is ignoring the right
and bottom edge of the rectangle area. Is there any logic behind this
behavior?
Thanks.
.
Relevant Pages
- Smooth scaling of System.Drawing.Pen object?
... The code below draws with a Graphics object that is ... If I draw a rectangle with a pen wider than 1 ... the resultant sides are just 1 pixel thick. ... (microsoft.public.dotnet.framework.drawing) - Re: GDI+, Pens and Draw*** methods
... will draw inside the rectangle. ... > code wholesale to GDI+. ... > Find great Windows Forms articles in Windows Forms Tips and Tricks ... >> Equals a 101 pixel wide box since 0 also counts as a pixel. ... (microsoft.public.dotnet.framework.drawing) - Re: Fast and simple way to determine bounds of difference...
... That should help with the basic transfer of pixel data. ... rectangle of the image difference, ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... (microsoft.public.dotnet.framework.drawing) - Re: GDI+, Pens and Draw*** methods
... provides a rectangle of 20*20 ... set out by GDI's rectangle method which draws the rectangle one pixel larger ... GDI+. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... (microsoft.public.dotnet.framework.drawing) - Re: Calculate the interior of a rectangle
... Apart from a slightly esoteric case which really doesn't have a bearing on this and which I won't therefore mention, a pixel is the smallest unit that can be addressed on the display. ... You also need to take into account which method you are using to draw your stuff, and in some cases you need to do that for all lines, even single pixel lines. ... For example, if you are using a single pixel line thickness and you draw a rectangle using the VB Line method with coordinates - you will not get exactly the same sized rectangle as you would get if you instead drew it using the API Rectangle method with exactly the same - coordinates. ... For example, if you draw a rectangle using such a pen then the rectangle coordinates you specify will effectively describe the outer edge of the lines of drawn rectangle, not the centre point, no matter how thick the line is. ... (microsoft.public.vb.general.discussion) |
|