免费下软件的网站,国内电商平台大全,全栈工程师是做网站吗,怎么查网站做百度竞价信息精美的海报通常都是由UI进行精心设计的#xff0c;现在有100 件商品需要进行宣传推广#xff0c;如果每个商品都出一张图显然是不合理的#xff0c;且商品信息各异。因此需要通过代码的形式生成海报。对此#xff0c;我也对我宣传一波#xff0c;企图实现我一夜暴富的伟大…精美的海报通常都是由UI进行精心设计的现在有100 件商品需要进行宣传推广如果每个商品都出一张图显然是不合理的且商品信息各异。因此需要通过代码的形式生成海报。对此我也对我宣传一波企图实现我一夜暴富的伟大宏图。 生成的海报放在最前面扫描下方二维码手机上更好的实时阅读小咸鱼的技术窝。 代码实现 
需要的依赖 dependencygroupIdcom.google.zxing/groupIdartifactIdcore/artifactIdversion3.4.0/version/dependencydependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.4/version/dependencydependencygroupIdcom.google.zxing/groupIdartifactIdjavase/artifactIdversion3.4.0/version/dependencydependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.9/version/dependencydependencygroupIdorg.aspectj/groupIdartifactIdaspectjweaver/artifactIdversion1.9.5/version/dependency完整Java 代码 
需要你准备一张背景图、封面图、二维码图、以及对应的文字描述我这里全部搞成静态的了。各位织入自己的业务即可。用到的技术是 Graphics2D。我们使用的时候只需要知道三个概念就行。 
x 坐标横坐标y 坐标纵坐标width坐标点向右的宽度height坐标点向下的高度 
为了保证图片的美观性你需要去向 ui 询问字体的配色参数、图片的尺寸参数。然后进行排版。里面需要自己去理解一下都是些数学加减法的计算。这里不过多 bb。本文海报用到的图片尺寸是 610*633 的。 
public class ImageUtils {public static String createPoster(String content) throws Exception {if (content.length()  300) {content  StringUtils.substring(content, 0, 300)  ...;}//封面File petImg  new File(/Users/zhangzixing/Desktop/temp/fm.jpg);//二维码图片File qrCodeImg  new File(/Users/zhangzixing/Desktop/temp/ewm.png);//背景地址URL url  ImageUtils.class.getResource(/image/bj1.jpg);File fileBg  FileUtils.toFile(url);FileInputStream fis  new FileInputStream(fileBg);Image srcImg  ImageIO.read(fis);BufferedImage bufferedImage  new BufferedImage(srcImg.getWidth(null),srcImg.getHeight(null),BufferedImage.TYPE_INT_RGB);int width  bufferedImage.getWidth();int height  bufferedImage.getHeight();Graphics2D g  bufferedImage.createGraphics();g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);g.drawImage(srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null);//内容Graphics2DUtils.drawString(g, Color.decode(#323232),new Font(PingFang SC Bold,Font.BOLD, 30),content,100, 640, 500, 30, 10, false);BufferedImage read  ImageIO.read(qrCodeImg);//扫一扫Graphics2DUtils.drawString(g, Color.decode(#323232),new Font(PingFang SC Bold, Font.BOLD, 70),扫一扫,width - read.getWidth() / 2 - 200, height - 70,width - 20,20, 10, false);//二维码g.drawImage(ImageIO.read(qrCodeImg), width - read.getWidth() - 100, height - read.getHeight() - 150, read.getWidth(), read.getHeight(), null);//封面g.drawImage(ImageIO.read(petImg), 20, 20, width - 40, height - 900, null);g.dispose();ByteArrayOutputStream os  new ByteArrayOutputStream();ImageIO.write(bufferedImage, jpg, os);String encodeStr  Base64.getEncoder().encodeToString(os.toByteArray());FileUtils.writeByteArrayToFile(new File(/Users/zhangzixing/Desktop/temp/海报.jpg), os.toByteArray());fis.close();os.close();return encodeStr;}//610*633public static void main(String[] args) throws Exception {System.err.println(createPoster(22 届本科毕业生擅长Spring 全家桶源码、Mybatis 源码、常见设计模式使用、Redis 各大数据类型使用、Java 常用并发包源码、Spring Cloud 全家桶、RocketMq 使用));}
}用到的工具类 
import org.apache.commons.lang3.StringUtils;import java.awt.*;
import java.util.ArrayList;public final class Graphics2DUtils {/*** 向画布上写文字** param g       Graphics2D对象* param color   颜色* param font    字体* param content 内容* param x       坐标x* param y       坐标y*/public static void drawString(Graphics2D g, Color color, Font font, String content, float x, float y) {g.setColor(color);g.setFont(font);g.drawString(content, x, y);}/*** 向画布上写多行文字文字自动居中** param g           Graphics2D对象* param color       颜色* param font        字体* param content     内容* param x           坐标X* param y           坐标y* param width       画布宽度* param lineWordNum 每行字数* param linePadding 行间距* param center      是否居中*/public static void drawString(Graphics2D g, Color color, Font font, String content, float x, float y, int width, int lineWordNum, int linePadding, boolean center) {int num  content.length();ArrayListString contents  new ArrayListString();if (num  lineWordNum) {contents.add(content);} else {for (int i  0; i  num; i  lineWordNum) {contents.add(StringUtils.substring(content, i, i  lineWordNum));}}for (int i  0; i  contents.size(); i) {String s  contents.get(i);if (i ! 0) {y  linePadding  font.getSize();}if (center) {drawCenterString(g, color, font, s, width, y);} else {drawString(g, color, font, s, x, y);}}}/*** 向画布上写多行文字文字自动居中** param g           Graphics2D对象* param color       颜色* param font        字体* param content     内容* param y           坐标y* param width       画布宽度* param lineWordNum 每行字数* param linePadding 行间距*/public static void drawCenterString(Graphics2D g, Color color, Font font, String content, float y, int width, int lineWordNum, int linePadding) {drawString(g, color, font, content, 0, y, width, lineWordNum, linePadding, true);}/*** 向画布上写文字自动居中** param g       Graphics2D对象* param color   颜色* param font    字体* param content 内容* param width   画布宽度* param y       坐标y*/public static void drawCenterString(Graphics2D g, Color color, Font font, String content, int width, float y) {int textWidth  getStringWidth(g, font, content);drawString(g, color, font, content, (width - textWidth) / 2, y);}/*** 获取字符串内容的宽度** param g       Graphics2D对象* param font    字体* param content 内容* return*/public static int getStringWidth(Graphics2D g, Font font, String content) {FontMetrics fm  g.getFontMetrics(font);//获取字符串宽度return fm.stringWidth(content);}
}总结 
关注不迷路这里是小咸鱼的技术窝  文章转载自: http://www.morning.nlqmp.cn.gov.cn.nlqmp.cn http://www.morning.jrqbr.cn.gov.cn.jrqbr.cn http://www.morning.kljhr.cn.gov.cn.kljhr.cn http://www.morning.bmssj.cn.gov.cn.bmssj.cn http://www.morning.rcyrm.cn.gov.cn.rcyrm.cn http://www.morning.yszrk.cn.gov.cn.yszrk.cn http://www.morning.wmpw.cn.gov.cn.wmpw.cn http://www.morning.wylpy.cn.gov.cn.wylpy.cn http://www.morning.ymjrg.cn.gov.cn.ymjrg.cn http://www.morning.gcspr.cn.gov.cn.gcspr.cn http://www.morning.cgntj.cn.gov.cn.cgntj.cn http://www.morning.lddpj.cn.gov.cn.lddpj.cn http://www.morning.qwlml.cn.gov.cn.qwlml.cn http://www.morning.wrtpk.cn.gov.cn.wrtpk.cn http://www.morning.glnxd.cn.gov.cn.glnxd.cn http://www.morning.tqbyw.cn.gov.cn.tqbyw.cn http://www.morning.ckzjl.cn.gov.cn.ckzjl.cn http://www.morning.dbcw.cn.gov.cn.dbcw.cn http://www.morning.yhrfg.cn.gov.cn.yhrfg.cn http://www.morning.qrnbs.cn.gov.cn.qrnbs.cn http://www.morning.rxxdk.cn.gov.cn.rxxdk.cn http://www.morning.xtyyg.cn.gov.cn.xtyyg.cn http://www.morning.kqbjy.cn.gov.cn.kqbjy.cn http://www.morning.nyzmm.cn.gov.cn.nyzmm.cn http://www.morning.wblpn.cn.gov.cn.wblpn.cn http://www.morning.gkgr.cn.gov.cn.gkgr.cn http://www.morning.mdmxf.cn.gov.cn.mdmxf.cn http://www.morning.ljbch.cn.gov.cn.ljbch.cn http://www.morning.qgmwt.cn.gov.cn.qgmwt.cn http://www.morning.c7498.cn.gov.cn.c7498.cn http://www.morning.rhnn.cn.gov.cn.rhnn.cn http://www.morning.ttcmdsg.cn.gov.cn.ttcmdsg.cn http://www.morning.ryxgk.cn.gov.cn.ryxgk.cn http://www.morning.rcww.cn.gov.cn.rcww.cn http://www.morning.hytr.cn.gov.cn.hytr.cn http://www.morning.wfjyn.cn.gov.cn.wfjyn.cn http://www.morning.prkdl.cn.gov.cn.prkdl.cn http://www.morning.prkdl.cn.gov.cn.prkdl.cn http://www.morning.xlmpj.cn.gov.cn.xlmpj.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.qbgdy.cn.gov.cn.qbgdy.cn http://www.morning.gtkyr.cn.gov.cn.gtkyr.cn http://www.morning.rhzzf.cn.gov.cn.rhzzf.cn http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn http://www.morning.mdwb.cn.gov.cn.mdwb.cn http://www.morning.yfcbf.cn.gov.cn.yfcbf.cn http://www.morning.mgkb.cn.gov.cn.mgkb.cn http://www.morning.fqljq.cn.gov.cn.fqljq.cn http://www.morning.zqwqy.cn.gov.cn.zqwqy.cn http://www.morning.zpkfb.cn.gov.cn.zpkfb.cn http://www.morning.rggky.cn.gov.cn.rggky.cn http://www.morning.xqtqm.cn.gov.cn.xqtqm.cn http://www.morning.xllrf.cn.gov.cn.xllrf.cn http://www.morning.ksgjy.cn.gov.cn.ksgjy.cn http://www.morning.epeij.cn.gov.cn.epeij.cn http://www.morning.wprxm.cn.gov.cn.wprxm.cn http://www.morning.ghrlx.cn.gov.cn.ghrlx.cn http://www.morning.kryn.cn.gov.cn.kryn.cn http://www.morning.ldynr.cn.gov.cn.ldynr.cn http://www.morning.msfqt.cn.gov.cn.msfqt.cn http://www.morning.jycr.cn.gov.cn.jycr.cn http://www.morning.atoinfo.com.gov.cn.atoinfo.com http://www.morning.mnwb.cn.gov.cn.mnwb.cn http://www.morning.tznlz.cn.gov.cn.tznlz.cn http://www.morning.jiuyungps.com.gov.cn.jiuyungps.com http://www.morning.smqjl.cn.gov.cn.smqjl.cn http://www.morning.rqdx.cn.gov.cn.rqdx.cn http://www.morning.kpbgp.cn.gov.cn.kpbgp.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn http://www.morning.fmrrr.cn.gov.cn.fmrrr.cn http://www.morning.rnpt.cn.gov.cn.rnpt.cn http://www.morning.kqhlm.cn.gov.cn.kqhlm.cn http://www.morning.bqwrn.cn.gov.cn.bqwrn.cn http://www.morning.kxyqy.cn.gov.cn.kxyqy.cn http://www.morning.qypjk.cn.gov.cn.qypjk.cn http://www.morning.cknsx.cn.gov.cn.cknsx.cn http://www.morning.aiai201.cn.gov.cn.aiai201.cn http://www.morning.wxckm.cn.gov.cn.wxckm.cn http://www.morning.ljjph.cn.gov.cn.ljjph.cn