public static void main(String[] args){
try { int width = 0; int height = 0; String name="Elisa Zhang"; String date="SEPTEMBER 1, 2016"; String intranetId="elisaz@163.com"; BufferedImage p_w_picpath = ImageIO.read(new File("c:\\Users\\ADMIN\\Desktop\\certification20-1.jpg")); Graphics2D g2d = p_w_picpath.createGraphics(); g2d.drawImage(p_w_picpath,0,0,null); g2d.setBackground(new Color(255,255,255)); g2d.setPaint(new Color(0,0,0)); g2d.clearRect(0, 0, width, height); g2d.setFont(new Font("Georgia",Font.PLAIN,54)); int wid= g2d.getFontMetrics().stringWidth(name); g2d.drawString(name,p_w_picpath.getWidth()/2-wid/2,280);//居中对齐 g2d.setFont(new Font("Georgia",Font.ROMAN_BASELINE,9)); g2d.drawString(date,430,395); g2d.dispose(); ImageIO.write(p_w_picpath, "jpg", new File("C:/certification/"+intranetId+".jpg")); } catch(Exception ex) { ex.printStackTrace(); } }