Scale fonts

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
anyone knows if a Font can be scaled only in one dimension (width or height).
The result would be a Font that would have the same height and double wide,
for
example.
Thanks
 
anyone knows if a Font can be scaled only in one dimension (width or
height).
The result would be a Font that would have the same height and double
wide,
for example.

I'm not aware of any way to do this directly from a Font. But you can
create a temporary bitmap to which to draw, and set the transform for the
Graphics obtained from that bitmap to do the scaling for you. For example:

void DrawScaledString(Graphics gfx, string str, Font font, Brush
brush, PointF ptf, float scaleX, float scaleY)
{
SizeF szf = gfx.MeasureString(str, font);
Bitmap bmp = new Bitmap((int)Math.Ceiling(szf.Width * scaleX),
(int)Math.Ceiling(szf.Height * scaleY), gfx);

using (Graphics gfxT = Graphics.FromImage(bmp))
{
gfxT.Transform = new
System.Drawing.Drawing2D.Matrix(scaleX, 0, 0, scaleY, 0, 0);
gfxT.DrawString(str, font, brush, new PointF());
}

gfx.DrawImage(bmp, ptf);
}

Hope that helps.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top