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

  • 相关阅读:
    flex space-between最后一行对齐问题的解决方案
    如何在父级下访问v-slot的值——vuejs
    flex下省略号的问题解决
    Typescript使用字符串联合类型代替枚举类型
    flex三个对齐属性的记忆方式
    JS中的slice()和splice()的区别以及记忆方式
    JS中的call,apply和bind及记忆方式
    Vue 还是 React 还是 Angular ?
    利用ES6的Promise.all实现至少请求多长时间
    .net core <environment> 不起作用
  • 原文地址:https://www.cnblogs.com/luofuxian/p/1759243.html
Copyright © 2011-2022 走看看