zoukankan      html  css  js  c++  java
  • 生成图片,保存到指定目录

    代码
            /// <summary>
            
    /// 将指定的联系号码转换成图片
             
    /// </summary>
            
    /// <param name="phone">联系号码</param>
            
    /// <param name="fileSaveDir">生成图片的保存路径</param>
            
    /// <returns>返回生成的图片的文件名</returns>
            public static string ConvertPhoneToImageAndSave(string phone, string fileSaveDir)
            {
                Bitmap image 
    = new System.Drawing.Bitmap((int)Math.Ceiling(15 * 0.76 * phone.Length), 25);
                Graphics g 
    = System.Drawing.Graphics.FromImage(image);
                
    try
                {
                    g.Clear(Color.White);
                    Font f 
    = new Font("Arial"15, FontStyle.Bold);
                    SolidBrush brush 
    = new SolidBrush(ColorTranslator.FromHtml("#0A3B7E"));
                    g.DrawString(phone, f, brush, 
    12);
                    Guid guid 
    = Guid.NewGuid();
                    
    string fileName = guid.ToString() + ".gif";
                    DirectoryInfo dir 
    = new DirectoryInfo(fileSaveDir);
                    
    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                    
    string fileFullName = dir.FullName + fileName;
                    image.Save(fileFullName);
                    
    return fileName;
                }
                
    catch
                {
                    
    return "";
                }
                
    finally
                {
                    g.Dispose();
                    image.Dispose();
                }
            }

  • 相关阅读:
    Git配置
    第一次作业
    第二次作业
    python目前最好用的IDE——pycharm
    九九乘法表
    python语言的优点和缺点
    Python高效编程的19个技巧
    Python中 filter | map | reduce | lambda的用法
    Python 代码优化常见技巧
    求逆序对
  • 原文地址:https://www.cnblogs.com/luofuxian/p/1759243.html
Copyright © 2011-2022 走看看