java生成图片进行套打功能
本文实例为大家分享了java生成图片进行套打的具体代码,供大家参考,具体内容如下
importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Graphics;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjava.util.Calendar;
importjavax.imageio.ImageIO;
importorg.junit.Test;
publicclassimgecreate{
@Test
publicvoidgraphicsGeneration(){
try{
intimageWidth=3507;//图片的宽度
intimageHeight=2480;//图片的高度
BufferedImageimage=newBufferedImage(imageWidth,imageHeight,
BufferedImage.TYPE_INT_RGB);
Graphicsgraphics=image.getGraphics();
graphics.setColor(Color.white);
graphics.fillRect(0,0,imageWidth,imageHeight);
graphics.setColor(Color.black);
graphics.setFont(newFont("宋体",Font.PLAIN,70));
Stringaddress="山东省飞史蒂夫肯德基首付款艰苦奋斗就胜多负少的飞电风扇";
//为控制字符串过长换行
graphics.drawString(address.substring(0,13),985,1416);
graphics.drawString(address.substring(13),985,1484);
Calendarnow=Calendar.getInstance();
//证书有效期为3年,所以截止日减去1天
now.set(Calendar.DATE,now.get(Calendar.DATE)-1);
now.add(Calendar.YEAR,3);//
BufferedImagesmall=ImageIO.read(newFile("D://t.jpg"));//生成的图片中插入另一张图片
graphics.drawImage(small,2524,943,385,385,null);
graphics.dispose();
createImage("D://test1.jpg",image);
}catch(Exceptione){
e.printStackTrace();
}
}
privatestaticvoidcreateImage(StringfileLocation,BufferedImageimage){
try{
ImageIO.write(image,"jpeg",newFile(fileLocation));
image.flush();
}catch(Exceptione){
e.printStackTrace();
}
}
publicstaticvoidmain(String[]args){
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。