ImageSharp报错

错误信息

System.MissingMethodException: Method not found: 'System.Span`1<SixLabors.ImageSharp.PixelFormats.Rgba32> SixLabors.ImageSharp.Memory.Buffer2D`1.GetRowSpan(Int32)'.

需要升级项目

原来仅升级了SixLabors.ImageSharp没有升级drawing,都升级到最新版本

原来代码

cs 复制代码
//构建字体//装载字体(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)));

修改后代码

cs 复制代码
//构建字体//装载字体(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

相关推荐
Crazy Struggle2 个月前
.NET 8 高性能跨平台图像处理库 ImageSharp
.net·imagesharp·图像库·图像处理库
依旧风轻5 个月前
iOS 开发中,异步渲染和异步绘制
ios·rendering·drawing