参考帖子
BufferedImage ImageOne = new BufferedImage(width2, height2,
BufferedImage.TYPE_INT_RGB); Graphics g = ImageOne.getGraphics();//g.fillRect(0, 0,width2, height2);
g.setColor(Color.BLACK); Font mFont = new Font("宋体", Font.PLAIN, 20); g.setFont(mFont); //String str = "添加文字测试"; FontMetrics fm = g.getFontMetrics(mFont); int textWidth = fm.stringWidth(str); //计算文字的宽度 g.drawString(str,(600-textWidth)/2, 100); //文字居中显示 g.drawImage(image,(600-image.getWidth())/2 , 500, null);//将二维码画入大图片中