SixLabors.ImageSharp 组件生成透明的电子签章图片

由于暂时没有发现SixLabors.ImageSharp组件中支持的生成透明背景的api,

先用以下手动的方式解决:

主要逻辑是:先加载电子签章图片,然后抠出来放到 新创建的透明背景的图片上

主要代码: 

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.PixelFormats;

namespace Tzkj.AppAuthAssist.WebApi.Controllers

{

        ///


        ///
        ///

        ///
        [HttpGet("generate-membership-certificate")]
        public IActionResult GenerateMembershipCertificateAsync([FromServices] FontCollection fontCollection,
            int numX = 700, int numY = 560, int nameX = 540, int nameY = 665, int yearX = 1488, int yearY = 1155,
            int mounthX = 1612, int mounthY = 1155, int DayX = 1706, int DayY = 1155, int imageX = 650, int imageY = 800)
{

            #region 以下是抠图生成透明背景图片
            //添加电子签章
            using var memoryStream = new MemoryStream();
            using var signaturesImg = Image.Load("Signatures.jpeg");
            //var transparentWhite = new Rgba32(255, 255, 255, 0);
            // 创建一个新图像,用于放置不包含背景色的内容
            using var extractedImage = new Image(signaturesImg.Width, signaturesImg.Height);
            extractedImage.Mutate(ctx => ctx.Fill(Color.T

你可能感兴趣的:(Abp,SixLabors,c#)