字体相对较小的图像上的 DrawString
DrawString on an image with relatively small font
我想创建一个 bmp 文件(在 C# 中),上面写有文本。此 bmp 非常小 (120*70),所需字体大小为 5。创建此 bmp 后,文本不可读。有办法解决这个问题吗?
我已经用过
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
但运气不好
成功的关键主要在于字体的选择。这似乎达到了极限:
它使用 smallest-pixel-7 font 并像这样写入位图:
string testText = "The quick brown fox <_>°|^ 123456789-0!";
using (Graphics G = Graphics.FromImage(bmp0))
using (Font font = new Font("Smallest Pixel-7", 10f))
{
G.TextContrast = 0;
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
G.DrawString(testText, font, Brushes.Black, new Point(20, 20));
}
大多数字符适合 5 像素高度,有些使用第 6 像素行,例如 'Q',我猜第 7 行用于引导..
请注意全部大写并注意他们的许可证! (也应该有免费软件字体..比如 here)
在我的测试中 AntiAliasGridFit
是最好的选择,比 AntiAlias
好得多:
Each character is drawn using its antialiased glyph bitmap with
hinting. Much better quality due to antialiasing, but at a higher
performance cost.
注2:位图的dpi分辨率与需要的字体大小直接相关。在第一个示例中,使用了 72 dpi。如果增加分辨率,则可以减小字体大小。
bmp0.SetResolution(150, 150);
下面的示例使用了 72dpi 和 9.6pt 的字体大小。
这里是各种其他字体的选择;如果您无法阅读您不想使用的字体系列;-)
(我每5个像素加了一条线,这样你就可以比较实际高度了。)
我想创建一个 bmp 文件(在 C# 中),上面写有文本。此 bmp 非常小 (120*70),所需字体大小为 5。创建此 bmp 后,文本不可读。有办法解决这个问题吗?
我已经用过
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
但运气不好
成功的关键主要在于字体的选择。这似乎达到了极限:
它使用 smallest-pixel-7 font 并像这样写入位图:
string testText = "The quick brown fox <_>°|^ 123456789-0!";
using (Graphics G = Graphics.FromImage(bmp0))
using (Font font = new Font("Smallest Pixel-7", 10f))
{
G.TextContrast = 0;
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
G.DrawString(testText, font, Brushes.Black, new Point(20, 20));
}
大多数字符适合 5 像素高度,有些使用第 6 像素行,例如 'Q',我猜第 7 行用于引导..
请注意全部大写并注意他们的许可证! (也应该有免费软件字体..比如 here)
在我的测试中 AntiAliasGridFit
是最好的选择,比 AntiAlias
好得多:
Each character is drawn using its antialiased glyph bitmap with hinting. Much better quality due to antialiasing, but at a higher performance cost.
注2:位图的dpi分辨率与需要的字体大小直接相关。在第一个示例中,使用了 72 dpi。如果增加分辨率,则可以减小字体大小。
bmp0.SetResolution(150, 150);
下面的示例使用了 72dpi 和 9.6pt 的字体大小。
这里是各种其他字体的选择;如果您无法阅读您不想使用的字体系列;-)
(我每5个像素加了一条线,这样你就可以比较实际高度了。)