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

浪淘沙2年前后端180
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和api 都同时支持登录身份判断属性写法

using Microsoft.AspNetCore.Mvc.Filters;namespace xxtsoft.Application.Filters{   ...

asp.net 取得邮政Ems物流数据

asp.net 取得邮政Ems物流数据

一、引用dllBouncyCastle.Crypto.rar二、SM4加密using System; using System.Collections.Generic; usi...

asp.net core postgresql 大数据高性能分页

 /// <summary> /// 分页:返回json格式,参数加密 /// </summary> /// <param nam...

asp.net core HttpClient 返回值

  public async Task<IActionResult> OnPostDown()   {  ...

点击按钮,禁用提示,加导出word

@page @model xxtsoft.Web.Entry.Pages.sysadmins.kh.kh_outModel @{     Lay...

asp.net core furion 返回错误信息

asp.net core furion 返回错误信息

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

发表评论    

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