I'm drawing labels to an image file. It all works perfectly, except the font size.
gfx.DrawString(
thisTempLabel.LabelText,
new System.Drawing.Font(
thisTempLabel.LabelFont,
(float)thisTempLabel.fontSize
),
Brushes.Black,
new PointF(thisTempLabel.x, thisTempLabel.y)
);
Problem is my users pick font sizes in PX, and System.Drawing.Font
requires an EM siz开发者_运维百科e. I don't know how to resolve this!
Can I render the text using pixels?
Finally figured it out for if anyone has same problem:
System.Drawing.Font MyFont = new System.Drawing.Font(
thisTempLabel.LabelFont,
((float)thisTempLabel.fontSize),
FontStyle.Regular,
GraphicsUnit.Pixel
);
GraphicsUnit.Pixel does it!
Just use 1 em = 16 pixels. So:
14px: 1 / 16 * 14 =
13px: 1 / 16 * 13 =
100px: 1 / 16 * 100 =
精彩评论