亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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??赡苁鞘褂迷撛O置導出的 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 關注
  • 187 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號