zoukankan      html  css  js  c++  java
  • 给图片加自定义字体水印

    处理前:
    处理后:

    代码:
    加水印可以用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);
                    }
                }
            }
  • 相关阅读:
    CSUST--3.14排位周赛第四场 (全解)
    CSUST--3.7排位周赛第三场 (全解)
    android 代码功能测试junit test
    Sqlite数据库创建、删除、降级笔记
    三种进程和线程数据共享模块方法Queue》Pipe》manager
    多线程实例
    信号量
    红绿灯模型
    linshiwendang12--匈牙利
    spring--注入类型--构造方法(不常用)
  • 原文地址:https://www.cnblogs.com/zhangjiang/p/2869951.html
Copyright © 2011-2022 走看看