serhio
serhio

Reputation: 28586

Preserve Font Size when scaling a Drawing

I do the following when drawing:

Matrix m = new Matrix()
m.Scale(_zoomX, _zoomY)

e.Graphics.Transform = m

e.Graphics.DrawLine(...) ' line representation '
e.Graphics.DrawString(...) ' line text '

Now, the text became also scaled. Is it possible to avoid it?

Upvotes: 0

Views: 161

Answers (4)

serhio
serhio

Reputation: 28586

In order to change only the point coordonates, use instead of:

e.Graphics.Transform = m

this one:

m.TransformPoints(points)

Upvotes: 1

David Rutten
David Rutten

Reputation: 4806

You'll have to undo the Graphics transform and draw your text with an Identity (or at least non scaling) transform.

Upvotes: 1

Denis Palnitsky
Denis Palnitsky

Reputation: 18387

Matrix work with image and do not distinguishes if it text or shape. If text position is not relevant, you can reset e.Graphics.Transform

 Matrix oldMAtrix = e.Graphics.Transform;
 e.Graphics.Transform = m;
 e.Graphics.DrawEllipse(new Pen(Color.Black), 20, 20, 20, 20);
 e.Graphics.Transform = oldMAtrix;
 e.Graphics.DrawString("text", this.Font, SystemBrushes.ControlText, 10, 10);

Upvotes: 1

Andrei Sosnin
Andrei Sosnin

Reputation: 730

  • Try to adjust the font to size/_zoom when drawing it

Upvotes: 1

Related Questions