import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.IndexColorModel;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream; import javax.imageio.ImageIO; /**
* 根据文本生成图片的工具
* @author Winter Lau
* @date 2009-7-30 下午12:58:26
*/
public class TextImageUtils { private final static IndexColorModel icm = createIndexColorModel(); static IndexColorModel createIndexColorModel() {
BufferedImage ex = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED);
IndexColorModel icm = (IndexColorModel) ex.getColorModel();
int SIZE = 256;
byte[] r = new byte[SIZE];
byte[] g = new byte[SIZE];
byte[] b = new byte[SIZE];
byte[] a = new byte[SIZE];
icm.getReds(r);
icm.getGreens(g);
icm.getBlues(b);
java.util.Arrays.fill(a, (byte)255);
r[0] = g[0] = b[0] = a[0] = 0; //transparent
return new IndexColorModel(8, SIZE, r, g, b, a);
} /**
* 生成电子邮件图片
* @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);
} /**
* 生成电话号码图片
* @param phone
* @param out
* @throws IOException
*/
public static void MakePhoneImage(String phone, 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.BOLD, 20);
g.setFont(mFont);
g.drawString(phone, 2, 19);
FontMetrics fm = g.getFontMetrics();
int new_width = fm.charsWidth(phone.toCharArray(), 0, phone.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(phone, 2, new_height-4);
ImageIO.write(nbi, "gif", out);
}
/**
* 生成产品关键特征
* @param attribute
* @param out
* @throws IOException
*/
public static void MakeProductAttribute(String attribute, 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("宋体", Font.BOLD, 13);
g.setFont(mFont);
g.drawString(new String(attribute), 2, 19);
FontMetrics fm = g.getFontMetrics();
int new_width = fm.charsWidth(attribute.toCharArray(), 0, attribute.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(attribute, 2, new_height-4);
ImageIO.write(nbi, "gif", out);
} public static void main(String[] args) throws IOException {
String num = "020-85551111";
FileOutputStream fos = new FileOutputStream("D:/phone.gif");
try{
MakePhoneImage(num, fos);
}finally{
fos.close();
}
String email = "xxxxx@oschina.net";
FileOutputStream fos2 = new FileOutputStream("D:/email.gif");
try{
MakeEmailImage(email, fos2);
}finally{
fos2.close();
}
}
}

使用图片方式显示email地址的更多相关文章

  1. 一个Android上的以滑动揭示的方式显示并切换图片的View

    SlideView是一个Android上的以滑动揭示的方式显示并切换图片的View,以视觉对比的方式把一套相似的图片展示出来. 示例 翻页图片揭示效果: 特性 设置一组(List<ImageIn ...

  2. Scroll View 控件以Thumbnail的方式显示一个目录的全部图片,相似图片浏览器

    MAC : XCode -> Scroll View 控件以Thumbnail的方式显示一个目录的全部图片,类似图片浏览器 STEP1:将两个目录复制到project里面ImageBrowser ...

  3. 【js】【图片显示】js控制html页面显示图片方式

    js控制html页面显示图片方式,只需要引入“jquery-1.11.2.min.js” js: /* 引用 <script src="jquery-1.11.2.min.js&quo ...

  4. vue 动态拼接地址,使用本地的图片不显示

    <el-col :span="4" v-for="(item, index) in listData" :key="index"> ...

  5. ueditor编辑文章时候,复制粘贴内容,原来的图片不能显示

    ueditor编辑文章时候.当现有文章有图片的时候, 再复制粘贴文本进去的时候.里面的图片就不能显示了, 编辑器查看文章Html代码,图片路径显示为:src="http://localhos ...

  6. 【转】Retina 屏幕下,网页图片的显示兼容

    感谢 Apple,带来了 Retina 屏幕的革命,让我们可以在电子显示屏上享受到印刷级的分辨率.由于分辨率的提升,网页中的文字.Flash 和 SVG 内容显示得比原来更加精细,但网页中的图片却变得 ...

  7. 如何在网页中提取Email地址

    开博好久了,今天第一次发表技术文档,之前总是将一些好的事例保存在电脑,时间久了找起来也很麻烦,所以还是放在博客里进行归类比较方便,这样也能将自己在学习过程中的一些心得体会分享给大家,也能给需要的人一点 ...

  8. WCF :IIS寄宿方式的Web地址、BaseAddress和EndPoint Address的关系

    对于在IIS中通过W3SVC或WAS寄宿的WCF Service,其在浏览器中显示的地址(Web地址),与其配置文件中的BaseAddress和EndPoint Address有什么关系呢?让我们来分 ...

  9. pbfunc外部函数扩展应用-直接在Datawindow中生成QR二维码,非图片方式

    利用pbfunc外部函数在Datawindow中直接生成QR二维码,非图片方式.需要注意以下面几点: Datawindow的DataObject的单位必须为像素(Pixels). Datawindow ...

随机推荐

  1. golang 多维哈希(map,hashmap)实践随笔

    有些场景使用多维哈希来存储数据,时间复杂度恒定,简单粗暴好用.这里记录一下. 如下是三维哈希的简单示意图,建议层数不要太多,否则时间久了,自己写的代码都不认识. 下图是三维哈希在内存的存储形式,has ...

  2. vue组件化编程

    vue文件包含3个部分 <template> <div></div> </template> <script> export default ...

  3. ld: i386 架构于输入文件 bar.o 与 i386:x86-64 输出不兼容

    报错:ld: i386 架构于输入文件 foo.o 与 i386:x86-64 输出不兼容 或者:ld: i386 architecture of input file `foo.o' is inco ...

  4. MapWinGIS使用

    .net语言中使用MapWinGIS.ocx http://www.cnblogs.com/kekec/archive/2011/03/30/1999709.html 基于MapWinGis的开发探索 ...

  5. day 2 给程序传递参数

    1.如何实现变化name name = "alex" print("欢迎%s前来指导学习"%name) 欢迎alex前来指导学习 2.sys.argv impo ...

  6. 使用element-ui 的table 渲染数据遇到的问题

    通常我们使用一个table 来渲染服务的返回来的数据时,数据结构一般都是按row 来返回的,并且表头也是固定的 但是如果接口返回的数据结构不是我们想要的,表头也不确定时,我们该如何解析数据,将数据进行 ...

  7. 二进制描述子 BRIEF(ORB), BRISK, FREAK

    二进制描述子设计原则体现在三个部分: 采样pattern 方向orientation compensation 配对sampling pairs ORB基于BRIEF: BRISK是用于OKVIS的描 ...

  8. 绝地求生大逃杀BE启动失败,应用程序无法正常启动

    今日更新绝地求生大逃杀后部分客户反馈绝地求生点击启动提示BE安装,应用程序无法启动 问题原因:经过排查发现,客户开启过超级工作站运行过游戏,在系统镜像包中保留了旧版的BE服务,致使新版BE无法安装,冲 ...

  9. 虚拟机安装win7 64位-完美解决-费元星

    安装虚拟机是为了安装一个oracle ,在本机安装 ,本机会卡死,不是每次启动电脑都用oralce,而且有时候服务是关不干净的,所以安装在虚拟机里,需要的时候在开启,特做此记录! 费元星版权Q[971 ...

  10. Updating Homebrew... 长时间不动解决方法

    确保你已安装Homebrew 依次输入下面的命令(注意:不要管重置部分的命令,这里原作者贴出来.我也贴出来是以防需要重置的时候有参考操作命令) 替换brew.git: cd "$(brew ...