zoukankan      html  css  js  c++  java
  • .net生成水印和缩略图

    • 引用NuGet :CodeCarvings.Piczard 

            /// <summary>
            /// 生成缩略图
            /// </summary>
            /// <param name="imageWidth">图片宽</param>
            /// <param name="imageHigh">图片高</param>
            /// <param name="sourePath">原图</param>
            /// <param name="savePath">保存路径</param>
            private static void CreateThumbnail(int imageWidth, int imageHigh, string sourePath, string savePath)
            {
                ImageProcessingJob ipj = new ImageProcessingJob();
                ipj.Filters.Add(new FixedResizeConstraint(imageWidth, imageHigh)); //
                ipj.SaveProcessedImageToFileSystem(sourePath, savePath, new JpegFormatEncoderParams());  
            }
            /// <summary>
            /// 生成水印
            /// </summary>
            /// <param name="imageWidth">生成后图片宽度</param>
            /// <param name="imageHigh">生成后图片高度</param>
            /// <param name="markimage">水印图</param>
            /// <param name="sourePath">原图*(需要添加水印的图片)</param>
            /// <param name="savePath">生成路径</param>
            private static void CreateThumbnail(int? imageWidth, int? imageHigh,string markimage, string sourePath, string savePath)
            {
                ImageWatermark mark = new ImageWatermark(markimage);
                mark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight;
                mark.Alpha = 50;
                ImageProcessingJob job = new ImageProcessingJob();
                job.Filters.Add(mark);
                if (!imageWidth.HasValue && !imageHigh.HasValue)
                {
                    job.Filters.Add(new FixedResizeConstraint(imageWidth.Value, imageHigh.Value));
                }    
                job.SaveProcessedImageToFileSystem(sourePath, savePath, new JpegFormatEncoderParams());
    
            }

    效果:

    生成验证码:

           /// <summary>
            /// 生成验证码
            /// </summary>
            /// <param name="verificationCode">验证码字符串</param>
            /// <param name="width">图片宽度</param>
            /// <param name="hight">图片高度</param>
            /// <param name="Fontsize">字体大小</param>
            /// <param name="degree">模糊度</param>
            /// <param name="SavePath">保存路径</param>
            public static void GetVerificationCode(string verificationCode,int width,int hight,int Fontsize,int degree,string SavePath)
            {
                using (MemoryStream ms = ImageFactory.GenerateImage(verificationCode, width, hight, Fontsize, degree))
                using (FileStream fs=File.OpenWrite(SavePath))
                {
                    ms.CopyTo(fs);
                }
            }

    来自B站:逆风微笑代码狗 

    https://www.bilibili.com/video/BV1Wb411G7yk

  • 相关阅读:
    XPath在python中的高级应用
    Python中 sys.argv[]的用法简明解释
    python format
    爬虫解析:XPath总结
    c#attribute特性
    .net随笔--不好归类的
    windows系统操作
    linux学习
    visual studio各种新建项目和新建项简介
    自定义界面和控件--基础
  • 原文地址:https://www.cnblogs.com/Zingu/p/14694741.html
Copyright © 2011-2022 走看看