我目前正在为 .NET Core 中的某些内容使用 C# 库“ImageSharp”,我想知道是否可以使用它对某些文本应用“内斜角”效果。我已经将我在单独的图形应用程序中创建的示例图像放在一起,以展示我想要实现的目标。它看起来像你在书封面上看到的凸起字母,在我的图形应用程序中,它被称为“内斜角”效果。这可能与 ImageSharp 吗?如果没有,是否有其他 C# 图像处理库可以做到这一点?
到目前为止,这是我为创建文本而编写的一种方法:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.PixelFormats;
public static void CreateTextPng(string SavePath, int Width, string Text)
{
var TheFont = new Font(SystemFonts.Find("Times New Roman"), 40, FontStyle.Bold);
var Size = TextMeasurer.Measure(Text, new RendererOptions(TheFont) { WrappingWidth = Width });
using (var TheImage = new Image<Rgba32>(Width, (int)Math.Round(Size.Height)))
{
TheImage.Mutate(delegate (IImageProcessingContext Processor)
{
var textGraphicsOptions = new TextGraphicsOptions(new GraphicsOptions(), new TextOptions
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
WrapTextWidth = TheImage.Width
});
Processor.DrawText(textGraphicsOptions, Text, TheFont, Color.Yellow, new PointF(0, TheImage.Height / 2));
//
//I think this is where the code to create the "inner bevel" effect would go, but I don't know what to put here...
//
});
TheImage.SaveAsPng(SavePath, new PngEncoder { CompressionLevel = PngCompressionLevel.BestCompression });
}
}
这是方法调用:
CreateTextPng("C:/dev/textexample.png", 400, "Good Omens: The Nice and Accurate Prophecies of Agnes Nutter, Witch");
这个斜角效果可以用 ImageSharp 完成吗?任何帮助,将不胜感激!