JAVA 图片合成

public static String imgSyn() throws Exception {
		File file = new File("C:\\Users\\Administrator\\Desktop\\222.jpg");
		File file2 = new File("C:\\Users\\Administrator\\Desktop\\111.jpg");
		String path = "C:\\Users\\Administrator\\Desktop\\";
		String name = DbUtil.getUUID32Str() + ".jpg";
		path = path + File.separator + name;
		// 人物照片
		Image src1 = javax.imageio.ImageIO.read(file);
		// 二维码图片
		Image src2 = javax.imageio.ImageIO.read(file2);

		// 创建一个画布,设置宽高(这里人物照片宽高就是画布宽高)
		BufferedImage thumbImage = new BufferedImage(704, 960, BufferedImage.TYPE_INT_RGB);
		Graphics2D g = thumbImage.createGraphics();

		// 绘制人脸图片
		g.drawImage(src1.getScaledInstance(704, 960, Image.SCALE_SMOOTH), 0, 0, null);

		// 绘制二维码图片(这里二维码的宽高就由人物照片决定好了,我这里二维码宽高都是照片的宽度四分之一,然后二维码位于照片右下角)
		g.drawImage(src2.getScaledInstance(166, 166, Image.SCALE_SMOOTH),518 , 774,null);
		// 获取项目的根路径
//		String path = request.getSession().getServletContext().getRealPath("/");
		// 使用uuid为图片生成一个名字

		BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(path));
		String formatName = path.substring(path.lastIndexOf(".") + 1);
		ImageIO.write(thumbImage,formatName , new File(path) );

		// 关闭输出流
		out.close();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值