| | |
| | |
|
| | | // 邀请好友图片
|
| | | public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
|
| | | InputStream erCodeInputStream, String targetPath) throws IOException {
|
| | | inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230);
|
| | | InputStream erCodeInputStream, String targetPath,String inviteCode) throws IOException {
|
| | | inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230, inviteCode);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * -二维码的纵坐标
|
| | | * @param size
|
| | | * -二维码的尺寸
|
| | | * @param inviteCode
|
| | | * -邀请码
|
| | | * @throws IOException
|
| | | */
|
| | | // 邀请好友图片
|
| | | public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
|
| | | InputStream erCodeInputStream, String targetPath, int pX, int pY, int size) throws IOException {
|
| | | InputStream erCodeInputStream, String targetPath, int pX, int pY, int size, String inviteCode)
|
| | | throws IOException {
|
| | | BufferedImage bgImage = ImageIO.read(urlInputStream);
|
| | | final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(),
|
| | | BufferedImage.TYPE_INT_RGB);
|
| | |
| | | int pPY = pY + size / 2 - portraitSize / 2;
|
| | | portraitImg = ImageUtil.portraitImg(g2d, portraitImg, pPX, pPY, portraitSize, portraitSize);// 头像长宽
|
| | |
|
| | | // 画邀请码(邀请码的大小与字体固定)
|
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | String st = "邀请码:" + inviteCode;
|
| | | int width = bgImage.getWidth();
|
| | | String os = System.getProperty("os.name");
|
| | | String fontBoldPath = "/usr/share/fonts/PingFang_Medium.ttf";
|
| | | if (os.toLowerCase().startsWith("win")) {
|
| | | fontBoldPath = "D:/PingFang_Medium.ttf";
|
| | | }
|
| | |
|
| | | Font boldFont = null;
|
| | | try {
|
| | | boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
|
| | | } catch (FontFormatException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | g2d.setFont(boldFont);
|
| | | g2d.setColor(new Color(0, 0, 0));
|
| | |
|
| | | FontMetrics fm = g2d.getFontMetrics(boldFont);
|
| | | int textLength = fm.stringWidth(st);
|
| | |
|
| | | int ax = (width - textLength) / 2;
|
| | | int ay = bgImage.getHeight() - 92 + boldFont.getSize() / 2 - 5;
|
| | |
|
| | | g2d.setColor(new Color(0, 0, 0));
|
| | | g2d.drawString(st, ax, ay);
|
| | |
|
| | | }
|
| | |
|
| | | OutputStream out = new FileOutputStream(new File(targetPath));
|
| | | ImageIO.write(targetImg, "JPEG", out);
|
| | | out.flush();
|