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){  


    }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值