public static void composeImg(String url,HttpServletRequest req){
try {
String serverPath = req.getServletContext().getRealPath("/").replace("\\", "/");
InputStream imagein=new FileInputStream(serverPath+"qrimage"+"\\"+"1.jpg");
InputStream imagein2=new FileInputStream(url);
BufferedImage image= ImageIO.read(imagein);
BufferedImage image2=ImageIO.read(imagein2);
Graphics g=image.getGraphics();
//图片2为背景,把图1放到图2上,坐标
g.drawImage(image2,image.getTileWidth()-image2.getWidth(),image.getHeight()-image2.getHeight(),image2.getWidth(),image2.getHeight(),null);
OutputStream outImage=new FileOutputStream(url);
JPEGImageEncoder enc= JPEGCodec.createJPEGEncoder(outImage);
enc.encode(image);
imagein.close();
imagein2.close();
outImage.close();
} catch (Exception e) {
e.printStackTrace();
}
//g.drawImage(image2,image.getWidth()-image2.getWidth(),image.getHeight()-image2.getHeight(),image2.getWidth(),image2.getHeight(),null);
}
最近在整理一些资源工具,放在网站分享 http://tools.maqway.com
欢迎关注公众号:麻雀唯伊 , 不定时更新资源文章,生活优惠,或许有你想看的