本文实例为大家分享了java生成图片进行套打的具体代码,供大家参考,具体内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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){
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/FORLOVEHUAN/article/details/81409127