![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
///
<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, 1 , 2 );
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();
}
}
/// 将指定的联系号码转换成图片
/// </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, 1 , 2 );
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();
}
}