错误信息
System.MissingMethodException: Method not found: 'System.Span`1<SixLabors.ImageSharp.PixelFormats.Rgba32> SixLabors.ImageSharp.Memory.Buffer2D`1.GetRowSpan(Int32)'.
需要升级项目
原来仅升级了SixLabors.ImageSharp没有升级drawing,都升级到最新版本
原来代码
//构建字体//装载字体(ttf)(而且字体一定要支持简体中文的)
var fonts = new FontCollection();
SixLabors.Fonts.FontFamily fontFamily = fonts.Install("/fonts/SourceHanSansK-Normal.ttf");
//设置为多行文本输出
SixLabors.Fonts.Font titleFont = new SixLabors.Fonts.Font(fontFamily, 60, SixLabors.Fonts.FontStyle.Regular);
//多行文本输出
var textOptions = new TextOptions()
{ApplyKerning = true,VerticalAlignment = VerticalAlignment.Top,HorizontalAlignment = HorizontalAlignment.Left,WrapTextWidth = 700
};
var graphicsOptions = new GraphicsOptions()
{Antialias = true
};
//沿着行尾的绕行路径绘制文本
var options = new SixLabors.ImageSharp.Drawing.Processing.DrawingOptions
{GraphicsOptions = graphicsOptions,TextOptions = textOptions
};
//开始绘制文字
imageTemple.Mutate(ctx => ctx.DrawText(options, goodModel.name, titleFont, SixLabors.ImageSharp.Color.Red, new SixLabors.ImageSharp.PointF(30, 1350)));
修改后代码
//构建字体//装载字体(ttf)(而且字体一定要支持简体中文的)
var fonts = new FontCollection();
SixLabors.Fonts.FontFamily fontFamily = fonts.Add("/fonts/SourceHanSansK-Normal.ttf");
//设置为多行文本输出
SixLabors.Fonts.Font titleFont = new SixLabors.Fonts.Font(fontFamily, 60, SixLabors.Fonts.FontStyle.Regular);
//多行文本输出
var graphicsOptions = new GraphicsOptions()
{Antialias = true
};
//沿着行尾的绕行路径绘制文本
var options = new SixLabors.ImageSharp.Drawing.Processing.DrawingOptions
{GraphicsOptions = graphicsOptions,
};
//开始绘制文字
imageTemple.Mutate(ctx => ctx.DrawText(options, goodModel.name, titleFont, SixLabors.ImageSharp.Color.Red, new SixLabors.ImageSharp.PointF(30, 1350)));
参考
https://stackoverflow.com/questions/76023548/imagesharp-watermark-net6
https://github.com/SixLabors/ImageSharp/issues/1237