当前位置: 首页 > news >正文

网站开发执行文档手机百度快照

网站开发执行文档,手机百度快照,信用平台网站建设建议,还有哪些网站做产品众筹精美的海报通常都是由UI进行精心设计的,现在有100 件商品需要进行宣传推广,如果每个商品都出一张图显然是不合理的,且商品信息各异。因此需要通过代码的形式生成海报。对此,我也对我宣传一波,企图实现我一夜暴富的伟大…

精美的海报通常都是由UI进行精心设计的,现在有100 件商品需要进行宣传推广,如果每个商品都出一张图显然是不合理的,且商品信息各异。因此需要通过代码的形式生成海报。对此,我也对我宣传一波,企图实现我一夜暴富的伟大宏图。

在这里插入图片描述

生成的海报放在最前面,扫描下方二维码,手机上更好的实时阅读小咸鱼的技术窝。

在这里插入图片描述

代码实现

需要的依赖

  <dependency><groupId>com.google.zxing</groupId><artifactId>core</artifactId><version>3.4.0</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.4</version></dependency><dependency><groupId>com.google.zxing</groupId><artifactId>javase</artifactId><version>3.4.0</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.9</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.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();ArrayList<String> contents = new ArrayList<String>();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.qdjiajiao.com/news/10183.html

相关文章:

  • 外国人的做视频网站吗百度网址安全中心
  • 网站改版是什么意思外包平台
  • 网站换模板有影响吗兰州网络推广关键词优化
  • 什么购物平台质量最好seo优化报价
  • wordpress 站群模板数据营销
  • 什么网站做外贸最多的it菜鸡网seo
  • 网站手机微信三合一怎么做网站百度不收录的原因
  • python网站开发实例教程电商平台运营方案思路
  • 有没有专门做蛋糕的网站推广关键词排名
  • 做网站开发用哪门语言合肥全网推广
  • 宜州做网站需要多少钱2023年8月新冠
  • 网站建设与管理案例...it行业培训机构一般多少钱
  • 专业网站建设微信网站定制网站制作多少钱
  • 主机屋网站搭建设置湖南网站托管
  • .net 网站自动登录全网优化推广
  • 旅游网站模板下载爱站网ip反查域名
  • 改行做网站销售营销方案100例
  • 石家庄网站建设推广公司报价百度一下搜索
  • 淘宝网站首页怎么做学it什么培训机构好
  • 建立网站的原因小学生收集的新闻10条
  • 网站动态添加广告怎么做的cps游戏推广平台
  • seo营销型网站设计要点培训心得体会1000字
  • 住建部网站2015年城市建设统计广东seo推广费用
  • 工厂招工信息苏州百度搜索排名优化
  • 有域名如何做网站软文推广范文
  • 什么网站做外链优化好whois查询 站长工具
  • 纯css做网站北京最新消息今天
  • 最近热点新闻事件2023长沙seo优化排名推广
  • 做网站的软件公司大数据统计网站
  • 山东济南最新疫情爆发成都seo外包