C# ImageMagick 使用自定义字体
C# ImageMagick using custom Fonts
我试图更改我的 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
方法中也是如此。我尝试在其他地方使用该字体并且在那里工作。
有人知道我该如何实施吗?
您还可以指定字体的完整路径而不是字体名称:
var readSettings = new MagickReadSettings()
{
Font = path
}
我试图更改我的 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
方法中也是如此。我尝试在其他地方使用该字体并且在那里工作。
有人知道我该如何实施吗?
您还可以指定字体的完整路径而不是字体名称:
var readSettings = new MagickReadSettings()
{
Font = path
}