zoukankan      html  css  js  c++  java
  • 绘制不同颜色的文本图片

            private Bitmap strToImage(string str)
            {
                Font f = new Font(new FontFamily("宋体"), 10, FontStyle.Regular);
                float fontSizeWidth = 96 / (72 / f.Size); // 字体实际像素宽度   
                float fontSizeHeight = 96 / (72 / f.Size); // 字体实际像素高度   
               
    
                //创建此大小的图片
                Bitmap bmp = new Bitmap(str.Length * (int)(fontSizeWidth), 22);
                Graphics g = Graphics.FromImage(bmp);
                int fIndex= str.IndexOf(findText);
                string startStr = str.Substring(0, fIndex);
              
                float y= (23- (int)fontSizeHeight) / 2;
                g.DrawString(startStr, f, new SolidBrush(System.Drawing.Color.Black), new PointF(fontSizeWidth / 2,y));
                float startLenth = startStr.Length * (int)(fontSizeWidth );
                g.DrawString(findText, f, new SolidBrush(System.Drawing.Color.Red), new PointF(startLenth, y));//绘制红字
                string enStr = str.Substring(fIndex + findText.Length);
                float findTxLenth = findText.Length * (int)(fontSizeWidth );
                g.DrawString(enStr, f, new SolidBrush(System.Drawing.Color.Black), new PointF(startLenth+findTxLenth , y));
                g.Save();
                g.Dispose();
                return bmp;
            }
    
  • 相关阅读:
    mongodb 记录
    php保存文件
    调用AngularJS的API
    angular修改数据
    大小写转换
    使用Properties类动态加载配置文件里的内容
    org.apache.commons.cli.Options
    Google guava和Apache commons
    orc格式文件
    shell的awk命令使用
  • 原文地址:https://www.cnblogs.com/bile/p/3173126.html
Copyright © 2011-2022 走看看