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

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


相关文章

Microsoft Visual Studio Installer Projects 2022的安装与使用

https://www.cnblogs.com/jiayezi/p/15740161.html...

JNTemplate 模板标签读取dt数据

一、模板标签using JinianNet.JNTemplate; private readonly SqlSugar.ISqlSugarClient _db;...

asp.net core furion 返回错误信息

asp.net core furion 返回错误信息

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

asp.net core [BindProperty] 用法

在 ASP.NET Core 中,[BindProperty] 是一种用于绑定模型属性的特性,通常与 Razor 页面配合使用。它会自动将请求中的表单数据绑定到页面模型的属性上,简化了手动从 Requ...

asp.net core return Content 返回可解析的html

return Content(     "<!DOCTYPE html><html><body&g...

asp.net core razor 获取当前url

 @Request.Scheme://@Request.Host/anysc/dd_ts_stu...

发表评论    

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