微信公眾號(hào)開發(fā)中,微商商城系統(tǒng)經(jīng)常會(huì)碰到要求系統(tǒng)自動(dòng)生成授權(quán)圖片,試想如果會(huì)員較多,一個(gè)個(gè)手工處理費(fèi)時(shí)費(fèi)力。
一般會(huì)有如下要求:
自定義背景圖
附帶二維碼
附帶文字信息
public String genQrcode(TMember member) throws Exception {
/** 生成二維碼,用于圖片合并 */
String url = WebConstants.PATH + "ucenter/member/inviteScan.do?inviteId=" + member.getId();
String logo = ContextUtil.getRealPath() + "/theme/wd/images/qrcode_logo.png";
String desDir = WebConstants.WEB_ROOT + "upload/code/";
String fileName = "code_" + member.getId() + ".jpg";
QRCodeUtil.encode(url, logo, desDir, fileName, true);
/** 生成推廣圖 */
String shareName = "share_" + member.getId() + ".jpg";
String qrcodeBg = ContextUtil.getRealPath() + "/theme/wd/images/qrcode_bg.png";
BufferedImage image1 = ImageIO.read(new File(qrcodeBg));
BufferedImage image2 = ImageIO.read(new File(WebConstants.WEB_ROOT + "upload/code/" + fileName));
BufferedImage combined = new BufferedImage(image1.getWidth(), image1.getHeight(), BufferedImage.TYPE_INT_RGB);
// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(image1, 0, 0, null);
g.drawImage(image2, 95, 600, 150, 150, null);
// paint both images, preserving the alpha channels
String uname = member.getUname();
Calendar cal = Calendar.getInstance();
cal.setTime(member.getInputDate());
cal.add(Calendar.YEAR, 3);
Font font = new Font("微軟雅黑", Font.BOLD, 16);
Color color = new Color(0, 0, 0);
g.drawImage(image1, 0, 0, null);
g.setFont(font);
g.setColor(color);
g.drawString(uname, 200, 385);
g.drawString(DateUtils.formatShortDate(cal.getTime()), 191, 495);
g.drawString(member.getOpenid(), 191, 525);
// Save as new image
ImageIO.write(combined, "JPG", new File(desDir, shareName));
return "upload/code/" + shareName;
}
- 版權(quán)所有:奇站網(wǎng)絡(luò) 轉(zhuǎn)載請(qǐng)注明出處
- 廈門奇站網(wǎng)絡(luò)科技有限公司,專業(yè)提供網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),小程序開發(fā),系統(tǒng)定制開發(fā)。
- 軟件開發(fā)咨詢熱線:吳小姐 13313868605