Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用自定义字体在图像上添加文本?_C#_Image_Fonts_Custom Font - Fatal编程技术网

C# 如何使用自定义字体在图像上添加文本?

C# 如何使用自定义字体在图像上添加文本?,c#,image,fonts,custom-font,C#,Image,Fonts,Custom Font,我想使用第三方字体(.ttf)。更改按钮上的字体是可行的,但仅仅绘制文本数据类型是不可行的。没有错误输出 PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("Axixa.otf"); Font fnt = new Font(pfc.Families[0], 8, FontStyle.Regular); button1.Font = fnt; // This code change font corr

我想使用第三方字体(
.ttf
)。更改按钮上的字体是可行的,但仅仅绘制文本数据类型是不可行的。没有错误输出

PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile("Axixa.otf");

Font fnt = new Font(pfc.Families[0], 8, FontStyle.Regular);
button1.Font = fnt; // This code change font correctly

Bitmap bmp = new Bitmap("1.png");

RectangleF rectf = new RectangleF(0, 0, bmp.Width, bmp.Height);

Graphics g = Graphics.FromImage(bmp);

g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
StringFormat format = new StringFormat()
{
    Alignment = StringAlignment.Center,
    LineAlignment = StringAlignment.Center
};
g.DrawString("123, 123", fnt, Brushes.Red, rectf, format);

g.Flush();
g.Save();

把你的问题用英语发到帕顿,我想这是俄语的线索,所以)试试这个设置
g.SmoothingMode
g.InterpolationMode
g.PixelOffsetMode
并删除格式设置。把事情减少到最低限度,并检查它们是否有效。同样,我也知道这一点,但不是“
g.DrawString()
询问位置”不起作用。没有错误输出。这不是对问题的一个有用的描述?会发生什么?没有输出,字体错误。。???