• 给图片加自定义字体水印


    处理前:
    处理后:

    代码:
    加水印可以用DrawString 方法
               FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                Image image = Image.FromStream(fs);
                fs.Close();
                Bitmap b = new Bitmap(image);
                Graphics graphics = Graphics.FromImage(b);
                Font font = GetFont(72);
                Color cl = Color.FromArgb(0, 64, 128);
                SolidBrush myBrush = new SolidBrush(cl);
                //加名字
                graphics.DrawString(name, font, myBrush, 450, 225);
    

      GetFont方法载入自定义字体文件       

    private Font GetFont(int size)
    {
    System.Drawing.Font fn = this.Font;
    FontFamily ff = pfc.Families[0];
    
    if (ff.IsStyleAvailable(FontStyle.Regular))
    {
    fn = new Font(ff, size, FontStyle.Regular);
    }
    if (ff.IsStyleAvailable(FontStyle.Bold))
    {
    fn = new Font(ff, size, FontStyle.Bold);
    }
    if (ff.IsStyleAvailable(FontStyle.Italic))
    {
    fn = new Font(ff, size, FontStyle.Italic);
    
    }
    return fn;
    }  
    

    如果字体文件(TTF格式)没安装,那么需要在程序启动时候载入

     private void LoadFont()
            {
                Stream fontStream = this.GetType().Assembly.GetManifestResourceStream("WindowsFormsApplication1.SaginawBold.ttf");
                byte[] fontdata = new byte[fontStream.Length];
                fontStream.Read(fontdata, 0, (int)fontStream.Length);
                fontStream.Close();
                unsafe
                {
                    fixed (byte* pFontData = fontdata)
                    {
                        pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
                    }
                }
            }
  • 相关阅读:
    arguments.callee
    vue的生命周期
    Vue中的v-cloak用法
    控制input只能输入数字和两位小数
    css3新单位vw、vh的使用详解
    关于图片的Base64编码
    Logic and Fault simulation
    scan design flow(二)
    scan design flow(一)
    异构计算
  • 原文地址:https://www.cnblogs.com/zhangjiang/p/2869951.html
Copyright © 2020-2023  润新知