• 将文字转换为文字图片实现方法


     

       //把文字转换成图片
                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;                   
                    }

           }

  • 相关阅读:
    详解package-lock.json的作用
    Cisco计网实验配置总结
    使用Vue制作了一个计算机网络中子网划分部分的简陋计算工具
    Prettier-Code Formater代码格式化插件使用教程
    Node.js中npx命令的使用方法、场景
    从几道题目带你深入理解Event Loop_宏队列_微队列
    简单模拟实现javascript中的call、apply、bind方法
    git使用说明书
    使用闭包模拟实现AMD模块化规范
    if执行后else if即使满足条件也不再执行
  • 原文地址:https://www.cnblogs.com/Chinarain/p/3821899.html
Copyright © 2020-2023  润新知