欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Java使用圖片顯示電子郵件地址

系統(tǒng) 1939 0

今天在逛oschina的時(shí)候看見(jiàn)里面有一個(gè)代碼分享的功能還不錯(cuò),紅薯老大貼出了一段代碼個(gè)人覺(jué)得很實(shí)用轉(zhuǎn)出來(lái)分享下。?
Java代碼?? 收藏代碼
  1. import ?java.awt.Color;??
  2. import ?java.awt.Font;??
  3. import ?java.awt.FontMetrics;??
  4. import ?java.awt.Graphics2D;??
  5. import ?java.awt.image.BufferedImage;??
  6. import ?java.awt.image.IndexColorModel;??
  7. import ?java.io.FileOutputStream;??
  8. import ?java.io.IOException;??
  9. import ?java.io.OutputStream;??
  10. ??
  11. import ?javax.imageio.ImageIO;??
  12. ??
  13. /** ?
  14. ?*?根據(jù)文本生成圖片的工具 ?
  15. ?*?@author?Winter?Lau ?
  16. ?*?@date?2009-7-30?下午12:58:26 ?
  17. ?*/ ??
  18. public ? class ?TextImageUtils?{??
  19. ??
  20. ???? private ? final ? static ?IndexColorModel?icm?=?createIndexColorModel();??
  21. ??
  22. ???? static ?IndexColorModel?createIndexColorModel()?{??
  23. ????????BufferedImage?ex?=? new ?BufferedImage( 1 ,? 1 ,?BufferedImage.TYPE_BYTE_INDEXED);??
  24. ????????IndexColorModel?icm?=?(IndexColorModel)?ex.getColorModel();??
  25. ???????? int ?SIZE?=? 256 ;??
  26. ???????? byte []?r?=? new ? byte [SIZE];??
  27. ???????? byte []?g?=? new ? byte [SIZE];??
  28. ???????? byte []?b?=? new ? byte [SIZE];??
  29. ???????? byte []?a?=? new ? byte [SIZE];??
  30. ????????icm.getReds(r);??
  31. ????????icm.getGreens(g);??
  32. ????????icm.getBlues(b);??
  33. ????????java.util.Arrays.fill(a,?( byte ) 255 );??
  34. ????????r[ 0 ]?=?g[ 0 ]?=?b[ 0 ]?=?a[ 0 ]?=? 0 ;? //transparent ??
  35. ???????? return ? new ?IndexColorModel( 8 ,?SIZE,?r,?g,?b,?a);??
  36. ????}??
  37. ??????
  38. ???? /** ?
  39. ?????*?生成電子郵件圖片 ?
  40. ?????*?@param?email ?
  41. ?????*?@param?out ?
  42. ?????*?@throws?IOException ?
  43. ?????*/ ??
  44. ???? public ? static ? void ?MakeEmailImage(String?email,?OutputStream?out)? throws ?IOException?{??
  45. ???????? int ?height?=? 22 ;??
  46. ????????BufferedImage?bi?=? new ?BufferedImage( 255 ,height,BufferedImage.TYPE_INT_RGB);??????????
  47. ????????Graphics2D?g?=?(Graphics2D)bi.getGraphics();??
  48. ????????Font?mFont?=? new ?Font( "Verdana" ,?Font.PLAIN,? 14 );??
  49. ????????g.setFont(mFont);??
  50. ????????g.drawString(email,? 2 ,? 19 );??
  51. ????????FontMetrics?fm?=?g.getFontMetrics();??
  52. ???????? int ?new_width?=?fm.charsWidth(email.toCharArray(),? 0 ,?email.length())?+? 4 ;??
  53. ???????? int ?new_height?=?fm.getHeight();??
  54. ????????BufferedImage?nbi?=? new ?BufferedImage(new_width,?new_height,???
  55. ????????????BufferedImage.TYPE_BYTE_INDEXED,?icm);??
  56. ????????Graphics2D?g2?=?(Graphics2D)nbi.getGraphics();??
  57. ????????g2.setColor( new ?Color( 0 , 0 , 0 , 0 )); //透明 ??
  58. ????????g2.fillRect( 0 , 0 ,new_width,new_height);??
  59. ????????g2.setFont(mFont);??
  60. ????????g2.setColor( new ?Color( 200 , 0 , 0 ));??
  61. ????????g2.drawString(email,? 2 ,?new_height- 4 );??
  62. ??
  63. ????????ImageIO.write(nbi,? "gif" ,?out);??
  64. ????}??
  65. ??
  66. ???? /** ?
  67. ?????*?生成電話號(hào)碼圖片 ?
  68. ?????*?@param?phone ?
  69. ?????*?@param?out ?
  70. ?????*?@throws?IOException ?
  71. ?????*/ ??
  72. ???? public ? static ? void ?MakePhoneImage(String?phone,?OutputStream?out)? throws ?IOException?{??
  73. ???????? int ?height?=? 22 ;??
  74. ????????BufferedImage?bi?=? new ?BufferedImage( 255 ,height,BufferedImage.TYPE_INT_RGB);??????????
  75. ????????Graphics2D?g?=?(Graphics2D)bi.getGraphics();??
  76. ????????Font?mFont?=? new ?Font( "Verdana" ,?Font.BOLD,? 20 );??
  77. ????????g.setFont(mFont);??
  78. ????????g.drawString(phone,? 2 ,? 19 );??
  79. ????????FontMetrics?fm?=?g.getFontMetrics();??
  80. ???????? int ?new_width?=?fm.charsWidth(phone.toCharArray(),? 0 ,?phone.length())?+? 4 ;??
  81. ???????? int ?new_height?=?fm.getHeight();??
  82. ????????BufferedImage?nbi?=? new ?BufferedImage(new_width,?new_height,??
  83. ????????????BufferedImage.TYPE_BYTE_INDEXED,?icm);??
  84. ????????Graphics2D?g2?=?(Graphics2D)nbi.getGraphics();??
  85. ????????g2.setColor( new ?Color( 0 , 0 , 0 , 0 )); //透明 ??
  86. ????????g2.fillRect( 0 , 0 ,new_width,new_height);??
  87. ????????g2.setFont(mFont);??
  88. ????????g2.setColor( new ?Color( 200 , 0 , 0 ));??
  89. ????????g2.drawString(phone,? 2 ,?new_height- 4 );????????
  90. ????????ImageIO.write(nbi,? "gif" ,?out);??
  91. ????}??
  92. ???? /** ?
  93. ?????*?生成產(chǎn)品關(guān)鍵特征 ?
  94. ?????*?@param?attribute ?
  95. ?????*?@param?out ?
  96. ?????*?@throws?IOException ?
  97. ?????*/ ??
  98. ???? public ? static ? void ?MakeProductAttribute(String?attribute,?OutputStream?out)? throws ?IOException{??
  99. ???????? int ?height?=? 22 ;??
  100. ????????BufferedImage?bi?=? new ?BufferedImage( 255 ,height,BufferedImage.TYPE_INT_RGB);??????????
  101. ????????Graphics2D?g?=?(Graphics2D)bi.getGraphics();??
  102. ????????Font?mFont?=? new ?Font( "宋體" ,?Font.BOLD,? 13 );??
  103. ????????g.setFont(mFont);??
  104. ????????g.drawString( new ?String(attribute),? 2 ,? 19 );??
  105. ????????FontMetrics?fm?=?g.getFontMetrics();??
  106. ???????? int ?new_width?=?fm.charsWidth(attribute.toCharArray(),? 0 ,?attribute.length())?+? 4 ;??
  107. ???????? int ?new_height?=?fm.getHeight();??
  108. ????????BufferedImage?nbi?=? new ?BufferedImage(new_width,?new_height,??
  109. ???????????BufferedImage.TYPE_BYTE_INDEXED,?icm);??
  110. ????????Graphics2D?g2?=?(Graphics2D)nbi.getGraphics();??
  111. ????????g2.setColor( new ?Color( 0 , 0 , 0 , 0 )); //透明 ??
  112. ????????g2.fillRect( 0 , 0 ,new_width,new_height);??
  113. ????????g2.setFont(mFont);??
  114. ????????g2.setColor( new ?Color( 200 , 0 , 0 ));??
  115. ????????g2.drawString(attribute,? 2 ,?new_height- 4 );??
  116. ????????ImageIO.write(nbi,? "gif" ,?out);??
  117. ????}??
  118. ??????
  119. ???? public ? static ? void ?main(String[]?args)? throws ?IOException?{??
  120. ????????String?num?=? "020-85551111" ;??
  121. ????????FileOutputStream?fos?=? new ?FileOutputStream( "D:/phone.gif" );??
  122. ???????? try {??
  123. ????????????MakePhoneImage(num,?fos);??
  124. ????????} finally {??
  125. ????????????fos.close();??
  126. ????????}??
  127. ????????String?email?=? "xxxxx@oschina.net" ;??
  128. ????????FileOutputStream?fos2?=? new ?FileOutputStream( "D:/email.gif" );??
  129. ???????? try {??
  130. ????????????MakeEmailImage(email,?fos2);??
  131. ????????} finally {??
  132. ????????????fos2.close();??
  133. ????????}??
  134. ????}??
  135. }??

Java使用圖片顯示電子郵件地址


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦?。。?/p>

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 欧美一级片免费看 | 日韩三区 | 欧美高清性色生活片免费观看 | 亚洲精品久久久一二三区 | 久久久久久全国免费观看 | 黑丝在线播放 | 日本在线播放不卡一区二区三区 | 欧美黄视频 | 欧美一区二区在线播放 | 2018中文字幕在线观看 | 日产国产欧美视频一区精品 | 激情综合婷婷久久 | 亚洲成人自拍偷拍 | 亚洲一区免费在线 | www伊人| 奇米视频在线 | 亚洲高清av | 亚洲一区二区免费视频 | 午夜激情影院 | 色橹橹欧美在线观看视频高清免费 | 产真a观专区 | 欧美18av| 图片区乱熟图片区小说 | 奇米在线观看视频 | 日本三级一区二区 | 国产一区二区在线免费观看 | 精品毛片| 亚洲精品久久久久久一区 | 日本人毛片 | 33eee在线视频免费观看 | 日韩少妇成熟A片无码专区 黄在线免费观看 | wankzhd| 日韩在线电影 | 国产在线精品一区 | 精品国产青草久久久久福利 | 午夜影院福利社 | 欧美在线视频一区 | 欧美jlzz18性欧美 | 国产视频在| 久久精品一区二区国产 | 黄色网页免费 |