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;                   
                    }

           }

  • 相关阅读:
    apicloud 运费计算js+页面
    css让字体细长
    vue 请求完接口后执行方法
    js监听当前页面再次加载
    用apicloud+vue的VueLazyload实现缓存图片懒加载
    git merge和git rebase的区别(转)
    yuan先生博客链接
    django组件之contenttype(一)
    Django的orm中get和filter的不同
    python第三方库requests详解
  • 原文地址:https://www.cnblogs.com/Chinarain/p/3821899.html
Copyright © 2011-2022 走看看