java中怎么生成图片并进行套打功能

这篇文章给大家介绍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){


}

关于java中怎么生成图片并进行套打功能就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

发布于 2021-06-13 23:18:44
收藏
分享
海报
0 条评论
175
上一篇:Flutter中如何实现动画效果 下一篇:Java中利用Tcp/ip连接多人交互聊天室的实现
目录

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码