0

我试图在我的 IMagick 项目中更改字体。我想使用自定义字体,但显然它不起作用!

这是我的代码:

            PrivateFontCollection modernFont = new PrivateFontCollection();

            modernFont.AddFontFile(path);

                var readSettings = new MagickReadSettings()
                {

                    FontFamily = "Walrus Bold",
                    FontPointsize = 130,
                    TextGravity = Gravity.Center,
                    StrokeColor = MagickColors.White,
                    StrokeWidth = 4,
                    BackgroundColor = MagickColors.Transparent,
                    Height = 150,
                    Width = 600 
                };
                using (var image = new MagickImage(path))
                {
                    using (var caption = new MagickImage($"caption:{idolname}", readSettings))
                    {
                        
                        image.Composite(caption, textWidth + 90, textHeight + 155, CompositeOperator.Over);

                        image.Write(path);
                    }
                }

我已经打印了字体的名称,就像modernfont.Families方法中的那样。我尝试在其他东西中使用该字体并且它在那里工作。

任何人都知道我该如何实现它?

4

1 回答 1

3

您还可以指定字体的完整路径而不是字体名称:

var readSettings = new MagickReadSettings()
{
    Font = path
}
于 2021-09-26T18:06:16.080 回答