On Mon, 28 May 2007 03:51:02 -0700, iklarri
<ik*****@discussions.microsoft.comwrote:
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