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. python兵器谱之re模块与正则表达式

    一.正则表达式 ·1.正则表达式的应用场景: 应用特有的规则,给我需要的符合规则的字符串,在字符串中只有符合条件的才会被匹配和从大段的字符串中提取需要的数据 ·匹配字符串的规则: ·1.字符串:用户输 ...

  2. 动态的GRE OVER IPSEC的实验模拟与分析

    此篇博客正在介绍的是下图中的Dynamic P2P GRE OVER IPSEC VPN: 为什么出现这种动态的GRE OVER IPSEC VPN技术呢? 首先在前面几篇博客中已经介绍过了,动态是为 ...

  3. Java学习笔记十七:Java中static使用方法

    Java中static使用方法 一:Java中的static使用之静态变量: 我们都知道,我们可以基于一个类创建多个该类的对象,每个对象都拥有自己的成员,互相独立.然而在某些时候,我们更希望该类所有的 ...

  4. SpaceVim 语言模块 lua

    原文连接: https://spacevim.org/cn/layers/lang/lua/ 模块简介 启用模块 快捷键 交互式编程 运行当前脚本 模块简介 这一模块为在 SpaceVim 中进行 l ...

  5. cocos2dx - ActionManager内存泄露

    ActionManager memory leak cocos2d-x3.7 都3.7了还有这样的bug,真是好难过,不过还是好开源的,谁都可以贡献一下 问题描述: 当创建一个node,并让它run一 ...

  6. php api_token 与 user_token 简析

    前言: --->非开放性平台 --->公司内部产品 接口特点汇总: 1.因为是非开放性的,所以所有的接口都是封闭的,只对公司内部的产品有效: 2.因为是非开放性的,所以OAuth那套协议是 ...

  7. Qt-QML-Slider-滑块-Style

    感觉滑块这个东西,可以算是一个基本模块了,在我的项目中也有这个模块,今天我将学一下一下滑块的使用以及美化工作. 想学习滑块,那就要先建立一个滑块,新建工程什么的这里就省略了,不会的可以看我前面的几篇文 ...

  8. 第五篇 Flask组件之SQLAchemy及Flask-SQLAlchemy插件/Flask-Script/Flask-migrate/pipreqs模块

    SQLAlchemy组件 一. 介绍 SQLAlchemy是一个基于Python实现的ORM框架.该框架建立在 DB API之上,使用关系对象映射进行数据库操作,简言之便是:将类和对象转换成SQL,然 ...

  9. 使用postman实现半自动化

    前些日子项目要上一个活动,其中有一个功能是幸运大转盘,用户可以随机抽奖,奖品有多种满减券及多种商品,但是奖品都是有抽中概率的,且有的商品还设置有库存,所以测试点便是测试抽奖的概率和库存.接下来拆分一下 ...

  10. Java 消息对列

    ActiveMQ入门实例   1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.5. ...