java生成图片进行套打功能
本文实例为大家分享了java生成图片进行套打的具体代码,供大家参考,具体内容如下
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Calendar;
import javax.imageio.ImageIO;
import org.junit.Test;
public class imgecreate{
@Test
public void graphicsGeneration() {
try {
int imageWidth = 3507;// 图片的宽度
int imageHeight = 2480;// 图片的高度
BufferedImage image = new BufferedImage(imageWidth, imageHeight,
BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.setColor(Color.white);
graphics.fillRect(0, 0, imageWidth, imageHeight);
graphics.setColor(Color.black);
graphics.setFont(new Font("宋体", Font.PLAIN, 70));
String address="山东省飞史蒂夫肯德基首付款艰苦奋斗就胜多负少的飞电风扇";
//为控制字符串过长换行
graphics.drawString(address.substring(0,13), 985,1416);
graphics.drawString(address.substring(13), 985,1484);
Calendar now = Calendar.getInstance();
//证书有效期为3年,所以截止日减去1天
now.set(Calendar.DATE, now.get(Calendar.DATE)-1);
now.add(Calendar.YEAR, 3);//
BufferedImage small = ImageIO.read(new File("D://t.jpg"));//生成的图片中插入另一张图片
graphics.drawImage(small, 2524, 943, 385,385, null);
graphics.dispose();
createImage("D://test1.jpg", image);
}catch(Exception e) {
e.printStackTrace();
}
}
private static void createImage(String fileLocation, BufferedImage image) {
try {
ImageIO.write(image, "jpeg" , new File(fileLocation));
image.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args){
}
以上是 java生成图片进行套打功能 的全部内容, 来源链接: utcz.com/z/313092.html