手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#实现将Email地址转成图片显示的方法
C#实现将Email地址转成图片显示的方法
摘要:本文实例讲述了C#实现将Email地址转成图片显示的方法。分享给大家供大家参考。具体实现方法如下:privatefinalstaticInd...

本文实例讲述了C#实现将Email地址转成图片显示的方法。分享给大家供大家参考。具体实现方法如下:

private final static IndexColorModel icm = createIndexColorModel(); /** * 生成电子邮件图片 * @param email * @param out * @throws IOException */ public static void MakeEmailImage(String email, OutputStream out) throws IOException { int height = 22; BufferedImage bi = new BufferedImage(255,height,BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D)bi.getGraphics(); Font mFont = new Font("Verdana", Font.PLAIN, 14); g.setFont(mFont); g.drawString(email, 2, 19); FontMetrics fm = g.getFontMetrics(); int new_width = fm.charsWidth(email.toCharArray(), 0, email.length()) + 4; int new_height = fm.getHeight(); BufferedImage nbi = new BufferedImage(new_width, new_height, BufferedImage.TYPE_BYTE_INDEXED, icm); Graphics2D g2 = (Graphics2D)nbi.getGraphics(); g2.setColor(new Color(0,0,0,0));//透明 g2.fillRect(0,0,new_width,new_height); g2.setFont(mFont); g2.setColor(new Color(200,0,0)); g2.drawString(email, 2, new_height-4); ImageIO.write(nbi, "gif", out); }

希望本文所述对大家的C#程序设计有所帮助。

【C#实现将Email地址转成图片显示的方法】相关文章:

c#实现输出本月的月历

C#实现窗体淡入淡出效果的方法总结

C#编程实现Excel文档中搜索文本内容的方法及思路

判断图片-判断位图是否是黑白图片的方法

.NET(C#):Emit创建异常处理的方法

C# 去除首尾字符或字符串的方法

C#中执行批处理文件(*.bat)的方法代码

c#在控制台输出彩色文字的方法

C#实现图片分割方法与代码

深入理解C#实现快捷键(系统热键)响应的方法

精品推荐
分类导航