C#实现将Email地址转成图片显示的方法
程序员文章站
2023-11-27 12:59:04
本文实例讲述了c#实现将email地址转成图片显示的方法。分享给大家供大家参考。具体实现方法如下:
private final static indexcolor...
本文实例讲述了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#程序设计有所帮助。