为了账号安全,请及时绑定邮箱和手机立即绑定

Graphis.DrawString 始终使用默认字体

Graphis.DrawString 始终使用默认字体

C#
天涯尽头无女友 2023-05-13 15:51:46
我有一个项目,我在其中创建了一个图像,其中围绕一个不可见的圆圈旋转了文本。绘图本身工作得很好。然而,似乎无论我使用什么字体,我总是得到相同的结果,这是我假设一些低质量的默认字体。这是代码:        Bitmap objBmpImage = new Bitmap(1000, 1000);        System.Drawing.Text.InstalledFontCollection installedFontCollection = new System.Drawing.Text.InstalledFontCollection();        FontFamily[] fontFamilies = installedFontCollection.Families;        System.Drawing.Font objFont = new System.Drawing.Font(fontFamilies.Where(x => x.Name == "Arial").FirstOrDefault(),10);        Graphics objGraphics = Graphics.FromImage(objBmpImage);        objGraphics.Clear(Color.Transparent);        float angle = (float)360.0 / (float)competences.Count();        objGraphics.TranslateTransform(500, 450);        objGraphics.RotateTransform(-90 - (angle / 3));        int nbComptetence = competences.Count();        int indexCompetence = 0;        foreach (T_Ref_Competence competence in competences)        {            byte r, g, b;            HexToInt(competence.T_Ref_CompetenceNiveau2.T_Ref_CompetenceNiveau1.Couleur, out r, out g, out b);            Brush brush = new System.Drawing.SolidBrush(Color.FromArgb(255,r,g,b));            if (indexCompetence * 2 < nbComptetence)            {                objGraphics.DrawString(competence.Nom, objFont, brush, 255, 0);                objGraphics.RotateTransform(angle);            }我使用这样安装的系列获取字体    System.Drawing.Text.InstalledFontCollection installedFontCollection = new System.Drawing.Text.InstalledFontCollection();    FontFamily[] fontFamilies = installedFontCollection.Families;    System.Drawing.Font objFont = new System.Drawing.Font(fontFamilies.Where(x => x.Name == "Arial").FirstOrDefault(),10);我尝试使用其他字体,但结果始终相同。有什么我想念的吗?如果不是,可能是什么原因?
查看完整描述

1 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

选项 1:更改文本呈现

objGraphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel

选项 2:更改抗锯齿模式

objGraphics.InterpolationMode=InterpolationMode.NearestNeighbor;

选项 3:更改图像的 DPI

如果您缩放输入图像然后以更高的 DPI 绘制文本,您将获得最佳结果。

位图的默认 DPI 是 96。可能是使用该设置导出的 JS 库。

如果你想要更流畅的字体渲染,你需要增加DPI,例如

objBmpImage.SetResolution(1200,1200);

如果这样做,您可能需要增加位图的像素数。

如果“丑陋”的文字刚好适合1000x1000的图片,你现在需要1000*1200/96=12500像素。

更改前(使用 Arial 10 pt):

24 像素宽 J

更改后(仍使用 Arial 10 pt):

180 像素宽 J

请注意,以厘米为单位的尺寸不会改变。所以它仍然会打印得很好。


查看完整回答
反对 回复 2023-05-13
  • 1 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信