zoukankan      html  css  js  c++  java
  • 将文字转换为文字图片实现方法

     

       //把文字转换成图片
                if (!string.IsNullOrEmpty(present_no)) //如果文字不为空
                {
                    try
                    {
                        if (!Directory.Exists(@sinpath))
                        {
                            Directory.CreateDirectory(@sinpath); //用于存在图片的路径不存在,则先生成。
                        }
                        //图片对象  初始化图片的宽度与高度           
                        System.Drawing.Bitmap image = new System.Drawing.Bitmap(150, 30);
                        //画板
                        Graphics g = Graphics.FromImage(image);
                        //文本样式
                        //Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
                        Font font = new System.Drawing.Font("Arial", 10, (System.Drawing.FontStyle.Regular));
                        //文本颜色与纹理
                        //System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0,0, image.Width, image.Height), Color.Red, Color.Red,0, true);
                        SolidBrush drawBrush = new SolidBrush(Color.Red); //文字颜色
                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, image.Width, image.Height);

                        //g.DrawString(wordstring要绘制的文本, font, brush, 2, 2);
                        //image.Save(filename保存路径)
                        g.DrawString(pnName, font, drawBrush, 5, 5);
                        string path = sinpath + "\" + present_no + ".jpg";
                        image.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    catch (Exception ex)
                    {
                        throw ex;                   
                    }

           }

  • 相关阅读:
    2017 ICPC沈阳站L
    (POJ 1990)Mowfest(确定不再来一发树状数组么?)
    (POJ 3067) Japan (慢慢熟悉的树状数组)
    (POJ 2549)Sumsets(折半枚举)
    图的高siao存储结构——链式前向星
    (HDU1317)XYZZY(Floyd+spfa)
    (POJ1182)食物链(带权并查集-附通用模板)
    (HDU 1231)最大连续子序列
    (HDU 1598) find the most comfortable road (并查集+最小生成树)
    Problem: The World Final II(NEUOJ1175)排序+动态规划
  • 原文地址:https://www.cnblogs.com/Chinarain/p/3821899.html
Copyright © 2011-2022 走看看