【问题标题】:C# ImageMagick using custom FontsC# ImageMagick 使用自定义字体
【发布时间】:2021-09-25 17:16:28
【问题描述】:

我试图更改 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 方法中的那样。我尝试在其他东西中使用该字体并且它在那里工作。

有人知道我该如何实现它吗?

【问题讨论】:

    标签: c# imagemagick


    【解决方案1】:

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

    var readSettings = new MagickReadSettings()
    {
        Font = path
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      相关资源
      最近更新 更多