我有一个很好的问题要问你。我搜索了所有的谷歌和 MSDN 并没有找到任何东西。
我正在尝试做一个程序,将字体导出到每个字符的单个 PNG 图像。我目前正在使用新的 Windows 字体Segoe UI Symbol对其进行测试。请注意我知道字体许可条款,我不会在互联网上分发该字体。
好吧,当我调用方法时,真正的问题发生了DrawString
,成员Graphics
。我将 unicode 整数值转换为 char,然后转换为字符串。我已经尝试将整数转换为 char withchar.ConvertFromUtf32()
和 with Convert.ToChar()
。
该程序在 26 个字符期间运行良好(从57344 = 0xE000开始),当我使用数值直到57370时才出现问题。在此之后,没有一个数字不是用白框字符写的。
经过一番搜索,我发现Font
构造函数的重载,带有属性gdiCharset
并尝试将其值用作 2,但什么也没发生。
我在下面为您显示源代码。拜托,如果有人可以帮助我,我会很高兴。
更新
当我使用转义序列时(比如"\uE1FF"
代替 char 转换它可以工作!但我不知道如何在 for 循环中制作转义序列。
Font segoe = new Font("Segoe UI Symbol", 800, FontStyle.Regular, GraphicsUnit.Pixel, 2);
Bitmap bmedidor = new Bitmap(1000, 1000, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics gmedidor = Graphics.FromImage(bmedidor);
// This line below doesn't matter, see the method DrawString
Size tamanho = gmedidor.MeasureString(char.ConvertFromUtf32(57344).ToString(), segoe).ToSize();
int[] reducoes = new int[6] {512, 256, 128, 64, 32, 16};
string caminho = "C:\\InoMetro";
for (int u = 57344; u < 57896; u++)
{
Bitmap caractere = new Bitmap(tamanho.Width, tamanho.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics criador = Graphics.FromImage(caractere);
criador.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
criador.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
criador.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
criador.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// Here we have the problem
criador.DrawString(Convert.ToChar(u).ToString(), segoe, new SolidBrush(Color.Black), new PointF(0, 0));
for (int r = 0; r < reducoes.Length; r++)
{
int taR = reducoes[r];
Bitmap reducao = new Bitmap(taR, taR, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics redutor = Graphics.FromImage(reducao);
redutor.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
redutor.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
redutor.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
redutor.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
redutor.DrawImage(caractere, 0, 0, taR, taR);
reducao.Save(caminho + "\\" + taR.ToString() + "\\" + u.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
}
}