给图片加自定义字体水印

处理前:
处理后:

代码:
加水印可以用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);
                }
            }
        }
原文地址:https://www.cnblogs.com/zhangjiang/p/2869951.html