Ana Mah
Ana Mah

Reputation: 77

how to resize polygon in C#?

I draw Polygon with this code:

Graphics surface;
surface = this.CreateGraphics();
SolidBrush brush = new SolidBrush(Color.Olive);
Point[] points = { new Point(50, 50), new Point(250, 50), new Point(50, 250) };
surface.FillPolygon(brush, points);

how to resize polygon Similar to the following?

Pic

Upvotes: 1

Views: 4460

Answers (2)

John Alexiou
John Alexiou

Reputation: 29264

Try this:

var g  = e.Graphics;
var points=new PointF[] { new PointF(0, 0), new PointF(1, 0), new PointF(0, 1) };

var st=g.SaveState();

g.TranslateTransform(100f, 100f);
g.ScaleTransform(40f, 40f);
g.FillPolygon(Brushes.Olive, points);
g.Transform=mx;

g.TranslateTransform(300f, 100f);
g.ScaleTransform(80f, 80f);
g.FillPolygon(Brushes.MediumOrchid, points);
g.Restore(st);

which draws to polygons of the same shape on different locations with different sizes.

Form

(red annotations added by me)

Upvotes: 4

Magus
Magus

Reputation: 1312

You have a couple options. A simple, rather silly solution would be to use linq:

double resizeValue = 1.5;
points.Select(x => new Point(x.X*resizeValue, x.Y*resizeValue);

That way is simple to understand, I think. May be better ways, but if this is all you're doing, it's probably sufficient.

Upvotes: 1

Related Questions