我正在使用透明背景的位圖上繪制一個字串,Graphics.DrawString()并且當字體大小小于 23 毫米時,我得到帶有黑色輪廓的文本(字體是用創建的GraphicsUnit.Millimeter)。
代碼:
Bitmap bmp = new Bitmap(2000, 2000);
Color alpha = Color.FromArgb(0, 0, 0, 0);
for (int x = 0; x < bmp.Width; x )
for (int y = 0; y < bmp.Height; y )
bmp.SetPixel(x, y, alpha);
Graphics g = Graphics.FromImage(bmp);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
Font labelFont = new Font("Cascadia Mono SemiBold", 23/*22*/, FontStyle.Regular, GraphicsUnit.Millimeter);
Brush brush = new SolidBrush(Color.White);
g.DrawString("Some text", labelFont, brush, 200, 200);
23 毫米單位字體:

22 毫米單位字體:

我嘗試使用TextRenderer,但這會繪制沒有透明背景的文本。
uj5u.com熱心網友回復:
此處提供的代碼存在多個問題:
- 由于多種原因,初始回圈適得其反:
- 嘗試用透明顏色填充位圖,但這已經是與新創建的位圖關聯的非顏色 (
Color.FromArb(0, 0, 0, 0)) - 使用
SetPixel()方法,該任務可能最慢的工具
- 嘗試用透明顏色填充位圖,但這已經是與新創建的位圖關聯的非顏色 (
