C#完成將Email地址轉成圖片顯示的辦法。本站提示廣大學習愛好者:(C#完成將Email地址轉成圖片顯示的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是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#法式設計有所贊助。