zoukankan      html  css  js  c++  java
  • 根据传入的文字生成图片 并保存

    很简单的代码,记录下,防止忘记。

    实现过程和生成验证码相似

    public void SavePhoneImg(string Phone, string path)
            {
                System.Drawing.Bitmap image = new System.Drawing.Bitmap(135, 25);
                Graphics g = Graphics.FromImage(image);
                try
                {
                    Font font = new System.Drawing.Font("楷体", 15, (System.Drawing.FontStyle.Bold));
                    System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(5, 5, image.Width, image.Height), Color.Black, Color.Black, 1.2f, true);
                    g.DrawString(Phone, font, brush, 2, 0);
                    //画图片的边框线 
                    g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
                    System.IO.FileStream ms = new System.IO.FileStream(path, FileMode.Create);
                    image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                }
                finally
                {
                    g.Dispose();
                    image.Dispose();
                }
            }
    代码
  • 相关阅读:
    Dll版本管理
    线程池ThreadPool
    关于sitemesh和freemark在struts2中的一些问题总结
    Google 怎么搜索
    android 设计模式
    android webview
    ios 基础数据类型
    android 常用
    android Handler vs Timer
    网站
  • 原文地址:https://www.cnblogs.com/bobo-pcb/p/3924694.html
Copyright © 2011-2022 走看看