开发者

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 beca开发者_开发百科me also scaled. Is it possible to avoid it?


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


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);


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


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

e.Graphics.Transform = m

this one:

m.TransformPoints(points)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜