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

浪淘沙1年前后端113
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());
 }


相关文章

ubuntu 删除asp.net core 8.0

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

SqlSugar 无实体更新

 #region 保存反馈回复  /// <summary>  /// 保存反馈回复  /// <...

短信发送

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

asp.net core HttpClient post ,get

1、postvar url = "https://api.dingtalk.com/v1.0/oauth2/userAccessToken";...

asp.net core furion 返回错误信息

asp.net core furion 返回错误信息

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

asp.net core 发送253短信

<form method="post">     <button type="submit...

发表评论    

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