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();
}
JAVA 图片合成
最新推荐文章于 2021-10-26 14:52:12 发布