首页 > 代码库 > JAVA awt 绘制图形
JAVA awt 绘制图形
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 image = ImageIO.read(new File("c:\\Users\\ADMIN\\Desktop\\certification20-1.jpg"));
Graphics2D g2d = image.createGraphics();
g2d.drawImage(image,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,image.getWidth()/2-wid/2,280);//居中对齐
g2d.setFont(new Font("Georgia",Font.ROMAN_BASELINE,9));
g2d.drawString(date,430,395);
g2d.dispose();
ImageIO.write(image, "jpg", new File("C:/certification/"+intranetId+".jpg"));
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
JAVA awt 绘制图形