源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C#实现将Email地址转成图片显示的方法

  • 时间:2022-04-02 15:55 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C#实现将Email地址转成图片显示的方法
本文实例讲述了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#程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部