Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Alan's test 4 - Smooth scaling of Pen object?

13 views
Skip to first unread message

Alan Cobb

unread,
May 7, 2006, 2:55:11 AM5/7/06
to
Hi,

The code below draws with a Graphics object that is
scaled differently horizontally (50x) and vertically
(10x). If I draw a rectangle with a pen wider than 1
pixel then the top and bottom are 5x thicker than
the sides. To compensate for that I scale the Pen
in the "opposite" way. That successfully makes all
4 sides of the rectangle draw with the same
thickness.

What I don't understand is the "threshold" effect
I see when increasing the width of the scaled pen.
The code below shows that for pen widths of 1 to 14
the resultant sides are just 1 pixel thick. When
the width reaches 15, the sides jump to 15 pixels
thick. Why can't I get sides with widths between
1 and 15 pixels?

Thanks,
Alan Cobb

------- Code below from Paint handler --------

this.ClientSize = new Size( 1000, 1000 );

// Horizontal and vertical are scaled differently:
//
float fHorizScaling = this.ClientSize.Width / 50000.0F;
float fVertScaling = this.ClientSize.Height / 10000.0F;

e.Graphics.ScaleTransform(
fHorizScaling, // 0.02 (= 1000/50000)
fVertScaling // 0.10 (= 1000/10000)
);

Pen oPen = new Pen(
Color.Green,
1 // Initial width of pen.
);

// Scale pen to compensate for the scaling of the Graphics
// object above, so that aspect ratio of pen is square again:

oPen.ScaleTransform(
1 / fHorizScaling, // 50 (= 1 / 0.02)
1 / fVertScaling // 10 (= 1 / 0.10)
);

//oPen.Width = 5; // Draws sides of rectangle 1 pixel thick.
//oPen.Width = 14; // Draws sides of rectangle 1 pixel thick.
oPen.Width = 15; // Draws sides of rectangle 15 pixel thick.
//oPen.Width = 20; // Draws sides of rectangle 20 pixel thick.
//oPen.Width = 50; // Draws sides of rectangle 50 pixel thick.

e.Graphics.DrawRectangle(
oPen,
5000, 500, // Origin X, Origin Y
40000, 9000 // Width, Height
);

0 new messages