java生成微信小程序分享海報(bào)(一)

生成微信小程序分享海報(bào)有兩種方式,一種是利用H5的canvas,另外一種是通過(guò)服務(wù)端合并圖像生成酒繁。我要介紹的是如何通過(guò)合并圖像生成分享海報(bào)导梆。
定義了兩個(gè)類(lèi)轨淌,分別是SharedImageUtil、PosterInfoUtil看尼。SharedImageUtil是分享朋友圈類(lèi)递鹉;PosterInfoUtil是海報(bào)信息類(lèi)。
兩個(gè)類(lèi)的源碼如下:

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;



import javax.imageio.*;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;
import java.awt.geom.Area;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* 分享朋友圈工具類(lèi)
*/
public class SharedImageUtil {
 private SharedImageUtil() {
     throw new IllegalStateException("Utility class");
 }

 /* 要放置的二維碼寬度 */
 public static final int QRCODE_WIDTH = 230;
 /* 要放置的二維碼長(zhǎng)度 */
 public static final int QRCODE_LENGTH = 230;
 /* 要放置的二維碼Y位置 往下為大值藏斩,往上為小值 */
 public static final int QRCODE_Y = 1070;
 /*要放置的二維碼X位置 往下為大值躏结,往上為小值 */
 public static final int QRCODE_X = 740;
 /* 要放置的頭像半徑 */
 public static final int PROFILE_RADIUS = 80;
 /* 要放置的頭像y坐標(biāo) */
 public static final int PROFILE_Y = 1056;
 /* 要放置的頭像X坐標(biāo) */
 public static final int PROFILE_X = 90;
 /* 昵稱(chēng)的Y位置 */
 public static final int FONT_Y = 1110;
 /*昵稱(chēng)的X位置*/
 public static final int FONT_X = 190;
 /* 推廣文案的Y位置 */
 public static final int COPYWRITER_Y = 1200;
 /* 推廣文案的X位置 */
 public static final int COPYWRITER_X = 150;
 /* 商店圖案Y位置 */
 public static final int SHOP_PIC_Y = 70;
 /*商店圖案位置*/
 public static final int SHOP_PIC_X = 93;
 /* 商店圖案寬度 */
 public static final int SHOP_PIC_WIDTH = 900;
 /* 商店圖案長(zhǎng)度 */
 public static final int SHOP_PIC_LENGTH = 950;





 /**
  * 裁剪圖片
  *
  * @param img          the img
  * @param originWidth  the origin width
  * @param originHeight the origin height
  * @return the buffered image
  * @throws Exception the exception
  */
 public static BufferedImage cutPicture(BufferedImage img, int originWidth, int originHeight) throws IOException {
     int width = img.getWidth();  // 原圖的寬度
     int height = img.getHeight();  //原圖的高度

     int newImageX = 0; // 要截圖的坐標(biāo)
     int newImageY = 0; // 要截圖的坐標(biāo)
     if (width > originWidth) {
         newImageX = (width - originWidth) / 2;
     }
     if (height > originHeight) {
         newImageY = height - originHeight;
     }
     return cutJPG(img, newImageX, newImageY, originWidth, originHeight);
 }

 /**
  * 圖片拉伸
  *
  * @param originalImage the original image
  * @param originWidth   the origin width
  * @param originHeight  the origin height
  * @return the buffered image
  * @throws Exception the exception
  */
 public static BufferedImage zoomPicture(String originalImage, int originWidth, int originHeight) {

     BufferedImage img = null;
     BufferedImage bufferedImage = null;
     try {
         // 原來(lái)的圖片
         img = ImageIO.read(new File(originalImage));
         int width = img.getWidth();  // 原圖的寬度
         int height = img.getHeight();  //原圖的高度

         int scaledWidth = width;
         int scaledHeight = height;
         // 如果不是正方形
         if (width == height) {
             // 按照originHeight進(jìn)行縮放
             scaledWidth = originHeight;
             scaledHeight = originHeight;
         } else {
             if (width > height) {
                 // 按照originHeight進(jìn)行縮放
                 scaledWidth = (scaledWidth * originHeight) / scaledHeight;
                 scaledHeight = originHeight;
             } else {
                 // 寬高比例
                 int originPercent = (originHeight * 100) / originWidth;
                 int newPercent = (height * 100) / width;
                 if (newPercent >= originPercent) {
                     // 按照originWidth進(jìn)行縮放
                     scaledWidth = originWidth;
                     scaledHeight = (originHeight * scaledWidth) / scaledWidth;
                 } else {
                     // 按照originHeight進(jìn)行縮放
                     scaledWidth = (scaledWidth * originHeight) / scaledHeight;
                     scaledHeight = originHeight;
                 }
             }
         }
         Image schedImage = img.getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH);
         // 新的圖片
         bufferedImage = new BufferedImage(scaledWidth, scaledHeight, img.getType());
         Graphics2D g = bufferedImage.createGraphics();
         // 繪制
         g.drawImage(schedImage, 0, 0, null);
         g.dispose();
     } catch (IOException e) {
         e.printStackTrace();
     }

     return bufferedImage;
 }

 /**
  * 進(jìn)行裁剪操作
  *
  * @param originalImage the original image
  * @param x             the x
  * @param y             the y
  * @param width         the width
  * @param height        the height
  * @return the buffered image
  * @throws IOException the io exception
  */
 public static BufferedImage cutJPG(BufferedImage originalImage, int x, int y, int width, int height) throws IOException {
     Iterator<ImageReader> iterator = ImageIO.getImageReadersByFormatName("jpg");
     ImageReader reader = iterator.next();
     // 轉(zhuǎn)換成字節(jié)流
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     // writeToJPEG(1080,originalImage,0.5f,outputStream);
     ImageIO.write(originalImage, "jpg", outputStream);
     InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
     ImageInputStream iis = ImageIO.createImageInputStream(is);
     reader.setInput(iis, true);
     ImageReadParam param = reader.getDefaultReadParam();
     Rectangle rect = new Rectangle(x, y, width, height);
     param.setSourceRegion(rect);
     return reader.read(0, param);
 }

 public static BufferedImage mergePicture(BufferedImage baseLayer,
                                          BufferedImage topLayer,
                                          String nickName,
                                          Integer locationX,
                                          Integer locationY,
                                          Integer size) throws IOException {

     return  mergePicture(baseLayer,topLayer,nickName,locationX,locationY,size,size);
 }
 /**
  * 合并頭像和昵稱(chēng)
  *
  * @param baseLayer
  * @param topLayer
  * @param nickName
  * @param locationX
  * @param locationY
  * @param locationWidth
  * @param locationLength
  * @return
  * @throws IOException
  */
 public static BufferedImage mergePicture(BufferedImage baseLayer,
                                          BufferedImage topLayer,
                                          String nickName,
                                          int locationX,
                                          int locationY,
                                          int locationWidth,
                                          int locationLength) throws IOException {




     int width = baseLayer.getWidth(null); //底圖的寬度
     int height = baseLayer.getHeight(null); //底圖的高度
     // 按照底圖的寬高生成新的圖片
     BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics g = image.createGraphics();
     g.drawImage(baseLayer, 0, 0, width, height, null);

     //int smallWidth = topLayer.getWidth(null);   // 上層圖片的寬度
     // 設(shè)置上層圖片放置的位置的坐標(biāo)及大小
     g.drawImage(topLayer, locationX, locationY, locationWidth, locationLength, null);
     if (nickName != null) {
         // 普通字體(ps:字體是微軟雅黑,linux不具備有狰域,需要安裝媳拴,)
         Font font = new Font("微軟雅黑", Font.PLAIN, 35);
         g.setFont(font);
         g.setColor(new Color(129, 129, 129));
         FontMetrics fm = g.getFontMetrics(font);
         // 字體放置的位置
         //int textWidth = fm.stringWidth(nickName);
         g.drawString(nickName, locationX + 100, 1110);
     }

     g.dispose();

     return image;
 }


 /**
  * 按指定的字節(jié)數(shù)截取字符串(一個(gè)中文字符占3個(gè)字節(jié),一個(gè)英文字符或數(shù)字占1個(gè)字節(jié))
  *
  * @param sourceString 源字符串
  * @param cutBytes     要截取的字節(jié)數(shù)
  * @return
  */
 public static String cutString(String sourceString, int cutBytes) {
     if (sourceString == null || "".equals(sourceString.trim())) {
         return "";
     }
     int lastIndex = 0;
     boolean stopFlag = false;
     int totalBytes = 0;
     for (int i = 0; i < sourceString.length(); i++) {
         String s = Integer.toBinaryString(sourceString.charAt(i));
         if (s.length() > 8) {
             totalBytes += 3;
         } else {
             totalBytes += 1;
         }
         if (!stopFlag) {
             if (totalBytes == cutBytes) {
                 lastIndex = i;
                 stopFlag = true;
             } else if (totalBytes > cutBytes) {
                 lastIndex = i - 1;
                 stopFlag = true;
             }
         }
     }
     if (!stopFlag) {
         return sourceString;
     } else {
         return sourceString.substring(0, lastIndex + 1);
     }
 }

 /**
  * 合并二維碼附帶使用說(shuō)明
  *
  * @param baseImage
  * @param qrcodeBufferImage
  * @param text
  * @param locationX
  * @param locationY
  * @param locationWidth
  * @param locationLength
  * @return
  * @throws IOException
  */
 public static BufferedImage mergeQrcode(BufferedImage baseImage,
                                         BufferedImage qrcodeBufferImage,
                                         String text,
                                         int locationX,
                                         int locationY,
                                         int locationWidth,
                                         int locationLength) throws IOException {


     // BufferedImage qrcodeBufferImage = ImageIO.read(qrcodeFile);

     int width = baseImage.getWidth(null); //底圖的寬度
     int height = baseImage.getHeight(null); //底圖的高度

     // 按照底圖的寬高生成新的圖片
     BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics g = image.createGraphics();
     g.drawImage(baseImage, 0, 0, width, height, null);

     // 設(shè)置上層圖片放置的位置的坐標(biāo)及大小兆览,坐標(biāo)居中
     g.drawImage(qrcodeBufferImage, locationX, locationY, locationWidth, locationLength, null);
     if (text != null) {
         // 普通字體
         Font font = new Font("微軟雅黑", Font.PLAIN, 25);
         g.setFont(font);
         g.setColor(new Color(129, 129, 129));
         FontMetrics fm = g.getFontMetrics(font);
         // 字體放置的位置
         //int textWidth = fm.stringWidth(nickName);
         g.drawString(text, 748, 1330);
     }
     g.dispose();
     return image;
 }

 /**
  * 圖片上添加文字
  *
  * @param src        the src
  * @param copywriter the copywriter
  * @return the buffered image
  * @throws Exception the exception
  */
 public static BufferedImage drawTextInImage(BufferedImage src, String copywriter) {
     int width = src.getWidth(null);
     int height = src.getHeight(null);
     BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics2D g = image.createGraphics();
     g.drawImage(src, 0, 0, width, height, null);

     // 長(zhǎng)度和位置
     Font font = new Font("微軟雅黑", Font.PLAIN, 35);
     g.setFont(font);
     FontMetrics fm = g.getFontMetrics(font);
     int textWidth = fm.stringWidth(copywriter);
     g.setColor(new Color(47, 47, 47));
     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     // 先按字節(jié)來(lái)?yè)Q行屈溉,英文單詞空格問(wèn)題暫時(shí)未考慮
     if (copywriter.getBytes().length > 63) {
         String firstLine = cutString(copywriter, 63);
         String secondLine = copywriter.substring(firstLine.length(), copywriter.length());
         g.drawString(firstLine, (width - fm.stringWidth(firstLine)) / 2, COPYWRITER_Y);
         g.drawString(secondLine, (width - fm.stringWidth(secondLine)) / 2, COPYWRITER_Y + 35);
     } else {
         g.drawString(copywriter, COPYWRITER_X, COPYWRITER_Y);
     }
     g.dispose();

     return image;
 }

 public static BufferedImage drawTextInImage(BufferedImage src, String copywriter, int x, int y) {
     int width = src.getWidth(null);
     int height = src.getHeight(null);
     BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics2D g = image.createGraphics();
     g.drawImage(src, 0, 0, width, height, null);

     // 長(zhǎng)度和位置
     Font font = new Font("微軟雅黑", Font.PLAIN, 35);
     g.setFont(font);
     FontMetrics fm = g.getFontMetrics(font);
     int textWidth = fm.stringWidth(copywriter);
     g.setColor(new Color(62, 62, 62));
     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     g.drawString(copywriter, x, y);
     g.dispose();

     return image;
 }

 /**
  * 方形轉(zhuǎn)為圓形
  *
  * @param img    the img
  * @param radius the radius 半徑
  * @return the buffered image
  * @throws Exception the exception
  */
 public static BufferedImage convertRoundedImage(BufferedImage img, int radius) {
     BufferedImage result = new BufferedImage(radius, radius, BufferedImage.TYPE_INT_ARGB);
     Graphics2D g = result.createGraphics();
     //在適當(dāng)?shù)奈恢卯?huà)圖
     g.drawImage(img, (radius - img.getWidth(null)) / 2, (radius - img.getHeight(null)) / 2, null);

     //圓角
     RoundRectangle2D round = new RoundRectangle2D.Double(0, 0, radius, radius, radius * 2, radius * 2);
     Area clear = new Area(new Rectangle(0, 0, radius, radius));
     clear.subtract(new Area(round));
     g.setComposite(AlphaComposite.Clear);

     //抗鋸齒
     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     g.fill(clear);
     g.dispose();

     return result;
 }

 /**
  * 圖像等比例縮放
  *
  * @param img     the img
  * @param maxSize the max size
  * @param type    the type
  * @return the scaled image
  */
 private static BufferedImage getScaledImage(BufferedImage img, int maxSize, int type) {
     int w0 = img.getWidth();
     int h0 = img.getHeight();
     int w = w0;
     int h = h0;
     // 頭像如果是長(zhǎng)方形:
     // 1:高度與寬度的最大值為maxSize進(jìn)行等比縮放,
     // 2:高度與寬度的最小值為maxSize進(jìn)行等比縮放
     if (type == 1) {
         w = w0 > h0 ? maxSize : (maxSize * w0 / h0);
         h = w0 > h0 ? (maxSize * h0 / w0) : maxSize;
     } else if (type == 2) {
         w = w0 > h0 ? (maxSize * w0 / h0) : maxSize;
         h = w0 > h0 ? maxSize : (maxSize * h0 / w0);
     }
     Image schedImage = img.getScaledInstance(w, h, Image.SCALE_SMOOTH);
     BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
     Graphics2D g = bufferedImage.createGraphics();
     g.drawImage(schedImage, 0, 0, null);
     return bufferedImage;
 }

 /**
  * 對(duì)頭像處理
  *
  * @param in   of  the image
  * @param radius the radius
  * @return the buffered image
  * @throws Exception the exception
  */
 public static BufferedImage createRoundedImage(InputStream in, int radius) {
     BufferedImage img = null;
     BufferedImage fixedImg = null;
     BufferedImage bufferedImage = null;
     try {
         img = ImageIO.read(in);
         // 1. 按原比例縮減
         fixedImg = getScaledImage(img, radius, 2);
         // 2. 居中裁剪
         fixedImg = cutPicture(fixedImg, radius, radius);
         // 3. 把正方形生成圓形
         bufferedImage = convertRoundedImage(fixedImg, radius);
     } catch (IOException e) {
         e.printStackTrace();
     }
     return bufferedImage;
 }

 /**
  * 對(duì)頭像處理
  * @param img
  * @param radius
  * @return
  */
 public static BufferedImage createRoundedImage(BufferedImage img , int radius) {
     BufferedImage fixedImg = null;
     BufferedImage bufferedImage = null;
     try {
         // 1. 按原比例縮減
         fixedImg = getScaledImage(img, radius, 2);
         // 2. 居中裁剪
         fixedImg = cutPicture(fixedImg, radius, radius);
         // 3. 把正方形生成圓形
         bufferedImage = convertRoundedImage(fixedImg, radius);
     } catch (IOException e) {
         e.printStackTrace();
     }
     return bufferedImage;
 }

 /**
  * 獲取遠(yuǎn)程網(wǎng)絡(luò)圖片信息
  * @param imageURL
  * @return
  */
 public static BufferedImage getRemoteBufferedImage(String imageURL) {
     URL url = null;
     InputStream is = null;
     BufferedImage bufferedImage = null;
     try {
         url = new URL(imageURL);
         is = url.openStream();
         bufferedImage = ImageIO.read(is);
     } catch (MalformedURLException e) {
         e.printStackTrace();
         System.out.println("imageURL: " + imageURL + ",無(wú)效!");
         return null;
     } catch (IOException e) {
         e.printStackTrace();
         System.out.println("imageURL: " + imageURL + ",讀取失敗!");
         return null;
     } finally {
         try {
             if (is!=null) {
                 is.close();
             }
         } catch (IOException e) {
             e.printStackTrace();
             System.out.println("imageURL: " + imageURL + ",流關(guān)閉異常!");
             return null;
         }
     }
     return bufferedImage;
 }

 /**
  * 生成海報(bào)
  * @param posterInfo
  */
 public static void makePoster(PosterInfoUtil posterInfo){

     try {
         BufferedImage backgroundImage = SharedImageUtil.getRemoteBufferedImage(posterInfo.getBackgroundUrl());
         BufferedImage avastarImage = SharedImageUtil.getRemoteBufferedImage(posterInfo.getAvastarUrl());
         BufferedImage qrCodeImage = SharedImageUtil.getRemoteBufferedImage(posterInfo.getQrCodeUrl());

         // 生成頭像圓角
         avastarImage = createRoundedImage(avastarImage,posterInfo.getAvastarSize());
         // 獲取背景圖寬高
         int width = backgroundImage.getWidth(null); //底圖的寬度
         int height = backgroundImage.getHeight(null); //底圖的高度

         // 按照底圖的寬高生成新的圖片
         BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
         Graphics g = image.createGraphics();
         g.drawImage(backgroundImage, 0, 0, width, height, null);
         // 設(shè)置頭像放置的位置的坐標(biāo)及大小,坐標(biāo)居中
         g.drawImage(avastarImage, posterInfo.getAvastarLocationX(), posterInfo.getAvastarLocationY(), posterInfo.getAvastarSize(), posterInfo.getAvastarSize(), null);
         // 設(shè)置二維碼放置的位置的坐標(biāo)及大小抬探,坐標(biāo)居中
         g.drawImage(qrCodeImage, posterInfo.getQrCodeLocationX(), posterInfo.getQrCodeLocationY(), posterInfo.getQrCodeSize(), posterInfo.getQrCodeSize(), null);

         // 字體顏色
         List<Integer> fontColors = posterInfo.getFontColors();
         // 設(shè)置文字
         if (posterInfo.getNickName() != null || posterInfo.getOtherText() != null){
             // 普通字體
             Font font = new Font("微軟雅黑", Font.PLAIN, posterInfo.getNickNameFontSize());
             g.setFont(font);
             g.setColor(new Color(fontColors.get(0), fontColors.get(1), fontColors.get(2)));
             FontMetrics fm = g.getFontMetrics(font);
             // 字體放置的位置
             g.drawString(posterInfo.getNickName(), posterInfo.getNickNameLocationX(), posterInfo.getNickNameLocationY());
         }

         if (posterInfo.getOtherText() != null){
             // 普通字體
             Font font = new Font("微軟雅黑", Font.PLAIN, posterInfo.getOtherTextFontSize());
             g.setFont(font);
             g.setColor(new Color(fontColors.get(0), fontColors.get(1), fontColors.get(2)));
             FontMetrics fm = g.getFontMetrics(font);
             // 字體放置的位置
             g.drawString(posterInfo.getOtherText(), posterInfo.getOtherTextLocationX(), posterInfo.getOtherTextLocationY());
         }
         g.dispose();
         ImageIO.write(image, "jpg", new File(posterInfo.getSavePath()));


     }catch (Exception e){
         e.printStackTrace();
     }

 }


}



import java.util.List;

/**
 * 海報(bào)信息
 */
public class PosterInfoUtil {
    private String qrCodeUrl  = "";
    private String backgroundUrl   = "";
    private String avastarUrl  = "";

    private Integer qrCodeSize  = 0;
    private Integer avastarSize  = 0;

    private Integer qrCodeLocationX  = 0;
    private Integer qrCodeLocationY  = 0;

    private Integer avastarLocationX  = 0;
    private Integer avastarLocationY  = 0;


    private String nickName  = "";
    private String otherText  = "";


    private Integer nickNameLocationX  = 0;
    private Integer nickNameLocationY  = 0;

    private Integer otherTextLocationX  = 0;
    private Integer otherTextLocationY  = 0;

    private Integer nickNameFontSize = 0;
    private Integer otherTextFontSize = 0;

    private String savePath  = "";

    public List<Integer> getFontColors() {
        return fontColors;
    }

    public void setFontColors(List<Integer> fontColors) {
        this.fontColors = fontColors;
    }

    private List<Integer> fontColors;
    public Integer getNickNameFontSize() {
        return nickNameFontSize;
    }

    public void setNickNameFontSize(Integer nickNameFontSize) {
        this.nickNameFontSize = nickNameFontSize;
    }

    public Integer getOtherTextFontSize() {
        return otherTextFontSize;
    }

    public void setOtherTextFontSize(Integer otherTextFontSize) {
        this.otherTextFontSize = otherTextFontSize;
    }




    public String getSavePath() {
        return savePath;
    }

    public void setSavePath(String savePath) {
        this.savePath = savePath;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getOtherText() {
        return otherText;
    }

    public void setOtherText(String otherText) {
        this.otherText = otherText;
    }

    public Integer getNickNameLocationX() {
        return nickNameLocationX;
    }

    public void setNickNameLocationX(Integer nickNameLocationX) {
        this.nickNameLocationX = nickNameLocationX;
    }

    public Integer getNickNameLocationY() {
        return nickNameLocationY;
    }

    public void setNickNameLocationY(Integer nickNameLocationY) {
        this.nickNameLocationY = nickNameLocationY;
    }

    public Integer getOtherTextLocationX() {
        return otherTextLocationX;
    }

    public void setOtherTextLocationX(Integer otherTextLocationX) {
        this.otherTextLocationX = otherTextLocationX;
    }

    public Integer getOtherTextLocationY() {
        return otherTextLocationY;
    }

    public void setOtherTextLocationY(Integer otherTextLocationY) {
        this.otherTextLocationY = otherTextLocationY;
    }




    public String getQrCodeUrl() {
        return qrCodeUrl;
    }

    public void setQrCodeUrl(String qrCodeUrl) {
        this.qrCodeUrl = qrCodeUrl;
    }

    public String getBackgroundUrl() {
        return backgroundUrl;
    }

    public void setBackgroundUrl(String backgroundUrl) {
        this.backgroundUrl = backgroundUrl;
    }

    public String getAvastarUrl() {
        return avastarUrl;
    }

    public void setAvastarUrl(String avastarUrl) {
        this.avastarUrl = avastarUrl;
    }

    public Integer getQrCodeSize() {
        return qrCodeSize;
    }

    public void setQrCodeSize(Integer qrCodeSize) {
        this.qrCodeSize = qrCodeSize;
    }

    public Integer getAvastarSize() {
        return avastarSize;
    }

    public void setAvastarSize(Integer avastarSize) {
        this.avastarSize = avastarSize;
    }

    public Integer getQrCodeLocationX() {
        return qrCodeLocationX;
    }

    public void setQrCodeLocationX(Integer qrCodeLocationX) {
        this.qrCodeLocationX = qrCodeLocationX;
    }

    public Integer getQrCodeLocationY() {
        return qrCodeLocationY;
    }

    public void setQrCodeLocationY(Integer qrCodeLocationY) {
        this.qrCodeLocationY = qrCodeLocationY;
    }

    public Integer getAvastarLocationX() {
        return avastarLocationX;
    }

    public void setAvastarLocationX(Integer avastarLocationX) {
        this.avastarLocationX = avastarLocationX;
    }

    public Integer getAvastarLocationY() {
        return avastarLocationY;
    }

    public void setAvastarLocationY(Integer avastarLocationY) {
        this.avastarLocationY = avastarLocationY;
    }
}

測(cè)試案例源碼如下:

      PosterInfoUtil posterInfoUtil = new PosterInfoUtil();
      List<Integer> colors = new ArrayList<>();
      colors.add(40);
      colors.add(40);
      colors.add(40);
      posterInfoUtil.setAvastarUrl("XXXXXX");
      posterInfoUtil.setQrCodeUrl("XXXXXXX");
      posterInfoUtil.setBackgroundUrl("XXXXXXXX");
      posterInfoUtil.setNickName("XXXXX");
      posterInfoUtil.setOtherText("XXXXX");
      posterInfoUtil.setNickNameFontSize(28);
      posterInfoUtil.setOtherTextFontSize(36);
      posterInfoUtil.setQrCodeSize(220);
      posterInfoUtil.setAvastarSize(80);
      posterInfoUtil.setQrCodeLocationX(640);
      posterInfoUtil.setQrCodeLocationY(1250);
      posterInfoUtil.setAvastarLocationX(50);
      posterInfoUtil.setAvastarLocationY(1320);
      posterInfoUtil.setNickNameLocationX(140);
      posterInfoUtil.setNickNameLocationY(1380);
      posterInfoUtil.setOtherTextLocationX(50);
      posterInfoUtil.setOtherTextLocationY(1460);
      posterInfoUtil.setSavePath("D:\\result.jpg");
      posterInfoUtil.setFontColors(colors);
      SharedImageUtil.makePoster(posterInfoUtil);
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末子巾,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子小压,更是在濱河造成了極大的恐慌线梗,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,490評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件怠益,死亡現(xiàn)場(chǎng)離奇詭異仪搔,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)溉痢,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)僻造,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)憋他,“玉大人,你說(shuō)我怎么就攤上這事髓削≈竦玻” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,830評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵立膛,是天一觀的道長(zhǎng)揪罕。 經(jīng)常有香客問(wèn)我,道長(zhǎng)宝泵,這世上最難降的妖魔是什么好啰? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,957評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮儿奶,結(jié)果婚禮上框往,老公的妹妹穿的比我還像新娘。我一直安慰自己闯捎,他們只是感情好椰弊,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,974評(píng)論 6 393
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著瓤鼻,像睡著了一般秉版。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上茬祷,一...
    開(kāi)封第一講書(shū)人閱讀 51,754評(píng)論 1 307
  • 那天清焕,我揣著相機(jī)與錄音,去河邊找鬼祭犯。 笑死秸妥,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的沃粗。 我是一名探鬼主播筛峭,決...
    沈念sama閱讀 40,464評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼陪每!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起镰吵,我...
    開(kāi)封第一講書(shū)人閱讀 39,357評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤檩禾,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后疤祭,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體盼产,經(jīng)...
    沈念sama閱讀 45,847評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,995評(píng)論 3 338
  • 正文 我和宋清朗相戀三年勺馆,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了戏售。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片侨核。...
    茶點(diǎn)故事閱讀 40,137評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖灌灾,靈堂內(nèi)的尸體忽然破棺而出搓译,到底是詐尸還是另有隱情,我是刑警寧澤锋喜,帶...
    沈念sama閱讀 35,819評(píng)論 5 346
  • 正文 年R本政府宣布些己,位于F島的核電站,受9級(jí)特大地震影響嘿般,放射性物質(zhì)發(fā)生泄漏段标。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,482評(píng)論 3 331
  • 文/蒙蒙 一炉奴、第九天 我趴在偏房一處隱蔽的房頂上張望逼庞。 院中可真熱鬧,春花似錦瞻赶、人聲如沸赛糟。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,023評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)虑灰。三九已至,卻和暖如春痹兜,著一層夾襖步出監(jiān)牢的瞬間穆咐,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,149評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工字旭, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留对湃,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,409評(píng)論 3 373
  • 正文 我出身青樓遗淳,卻偏偏與公主長(zhǎng)得像拍柒,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子屈暗,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,086評(píng)論 2 355