tags:

views:

43

answers:

4

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?

+1  A: 
  • Try to adjust the font to size/_zoom when drawing it
deemoowoor
well... maybe, but I have `zoomX` and `zoomY` but the font have only `Size`...
serhio
+1  A: 

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);
Orsol
I shoudl use `e.Graphics.ResetTransform()` then `p = New PointF(_ZoomX * oldp.X, oldp.Y * _ZoomY)`
serhio
+1  A: 

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

David Rutten
the text position is important...
serhio
Yes, you'll have to do the math yourself to transform the text insertion position into the scaled matrix. But you cannot draw the text with a scaling matrix active.
David Rutten
+1  A: 

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

e.Graphics.Transform = m

this one:

m.TransformPoints(points)
serhio