C#實現(xiàn)將Email地址轉(zhuǎn)成圖片顯示的方法
更新時間:2015年06月16日 15:54:03 作者:紅薯
這篇文章主要介紹了C#實現(xiàn)將Email地址轉(zhuǎn)成圖片顯示的方法,涉及C#操作圖片的相關技巧,需要的朋友可以參考下
本文實例講述了C#實現(xiàn)將Email地址轉(zhuǎn)成圖片顯示的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
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#使用channel實現(xiàn)Plc異步任務之間的通信
在C#的并發(fā)編程中,Channel是一種非常強大的數(shù)據(jù)結(jié)構(gòu),用于在生產(chǎn)者和消費者之間進行通信,本文將給大家介紹C#使用channel實現(xiàn)Plc異步任務之間的通信,文中有相關的代碼示例供大家參考,感興趣的朋友跟著小編一起來看看吧2024-05-05
c# 動態(tài)加載dll文件,并實現(xiàn)調(diào)用其中的方法(推薦)
下面小編就為大家?guī)硪黄猚# 動態(tài)加載dll文件,并實現(xiàn)調(diào)用其中的方法(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02

