You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Graphics.DrawString绘制透明背景文本时小字号出现黑边问题

问题:透明背景Bitmap上绘制小字号文本出现黑色轮廓

我使用Graphics.DrawString()在透明背景的Bitmap上绘制文本时发现,当字体大小小于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毫米字号效果:
23mm字体

22毫米字号效果:
22mm字体

我尝试使用TextRenderer,但它无法绘制透明背景的文本。

内容的提问来源于stack exchange,提问作者Yotic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 07:50:29