asp.net core 图片左下角 加水印

浪淘沙11个月前后端71
using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Processing;

 string _pic = Path.Combine(App.WebHostEnvironment.WebRootPath + pic);           

 string fontPath = Path.Combine(App.WebHostEnvironment.WebRootPath + "/font/simhei.ttf");

 using (var image = Image.Load(_pic)) // 加载图片
 {
   
     // 加载字体
     var fontCollection = new FontCollection();
     var fontFamily = fontCollection.Add(fontPath);
     var font = fontFamily.CreateFont(30, FontStyle.Regular); // 字体大小为36

     // 设置水印颜色
     var watermarkColor = Color.FromRgba(255, 0, 0, 128); // 半透明白色

     var position = new PointF(
     10, // 距离左侧边距 10 像素
     image.Height - 150 // 距离底部边距 50 像素
 );

     // 在图片上添加水印
     image.Mutate(ctx => ctx.DrawText(userxm+"\n"+DateTime.Now+"\n"+ formatted_address, font, watermarkColor, position));

     // 保存图片
     image.Save(_pic, new JpegEncoder());
 }


相关文章

asp.net core razor 读取form中,同一name的值 分解

asp.net core razor 读取form中,同一name的值 分解

@page @model xxtsoft.Web.Entry.Pages.sysadmins.mb.mbModel @{     Layout&...

asp.net core furion 返回错误信息

asp.net core furion 返回错误信息

  if (string.IsNullOrEmpty(jd) || string.IsNullOrEmpty(wd))   {...

导出excel

@page @model xxtsoft.Web.Entry.Pages.test2Model @{ } <form method="post"&...

asp.net core razor加载模板文件路径

  var templateContent = "${include(\"" + App.HostE...

ubuntu 删除asp.net core 8.0

1. 查找已安装的 ASP.NET Core 8.0 版本dotnet --list-runtimes dotnet --list-sdks2. 删除 ASP.NET Core...

取消 "将 null 文本或可能的 null 值转换为不可为 null 类型。 "提示

在 .csproj 文件中添加或修改:<PropertyGroup>  <Nullable>disable</Nullable></Pro...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。