少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
package com.abin.lee.wechat;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.imageio.stream.FileImageOutputStream;
public class WeChatPhoto {
public String createzPicture(Map<String,String> request){
String timeStamp=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new java.util.Date());
File fileOne = new File("E:\\pament\\wechat\\photo\\"+timeStamp+".png");
try {
BufferedImage d = ImageIO.read(new File("E:\\pament\\wechat\\photo\\flight-model.png"));
Graphics2D graohics =d.createGraphics();
//写字往图片上面
String startPlace=request.get("startPlace");
String arrivalPlace=request.get("arrivalPlace");
String flightNo=request.get("flightNo");
String startTime=request.get("startTime");
String arrivalTime=request.get("arrivalTime");
Font font = new Font("粗体", Font.PLAIN, 18);// 添加字体的属性设置
graohics.setColor(Color.BLACK);
graohics.setFont(font);
graohics.drawString(flightNo, 300, 20);
graohics.drawString(startPlace, 30, 100);
graohics.drawString(arrivalPlace, 555, 100);
graohics.drawString(startTime, 50, 145);
graohics.drawString(arrivalTime, 600, 145);
ImageIO.write(d, "png", new FileImageOutputStream(fileOne));
} catch (Exception e) {
e.printStackTrace();
}
return timeStamp;
}
public static void main(String[] args) {
WeChatPhoto we=new WeChatPhoto();
Map<String,String> request=new HashMap<String, String>();
request.put("startPlace", "北京首都T2");
request.put("arrivalPlace", "上海虹桥T1");
request.put("startTime", "08:58");
request.put("arrivalTime", "10:23");
request.put("flightNo", "MU5183");
String timeStamp=we.createzPicture(request);
System.out.println("timeStamp="+timeStamp);
}
}
posted on 2013-06-07 17:32 abin 阅读(370) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: