Browse Source

情报板图片生成工具

develop
lau572 9 months ago
parent
commit
1f9a8ee4ab
  1. 57
      zc-business/src/main/java/com/zc/business/utils/BoardContentUtils.java

57
zc-business/src/main/java/com/zc/business/utils/BoardImageUtils.java → zc-business/src/main/java/com/zc/business/utils/BoardContentUtils.java

@ -15,14 +15,16 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 情报板生成图片工具
*/
public class BoardImageUtils {
public class BoardContentUtils {
private static final Logger log = LoggerFactory.getLogger(BoardImageUtils.class);
private static final Logger log = LoggerFactory.getLogger(BoardContentUtils.class);
//分辨率 宽度
private static final int width = 768;
@ -31,8 +33,8 @@ public class BoardImageUtils {
private static final int height = 64;
//图标地址
private static final String templatePath = "D:\\ruoyi\\uploadPath\\boardTemplate";
// private static final String templatePath = RuoYiConfig.getBoardPath();
// private static final String templatePath = "D:\\ruoyi\\uploadPath\\boardTemplate";
private static final String templatePath = RuoYiConfig.getBoardPath();
/**
* 事件场景
@ -53,6 +55,15 @@ public class BoardImageUtils {
//背景颜色
g.setBackground(Color.BLACK);
list.add(ImageDTO.createImageDTO("前方5公里发生事故缓行10分钟",new Color(255,0,0),new Font("Default", Font.BOLD, 22), 34, 0));
//设置颜色
g.setColor(new Color(255,0,0));
//设置字体
g.setFont(new Font("Default", Font.BOLD, 22));
String text = "前方" + "公里发生事故";
g.drawString(text, 34, 0); //画出水印
//编辑图片,插入要素
for (ImageDTO imgDTO : list) {
if (imgDTO.getType() == 0) {
@ -67,7 +78,7 @@ public class BoardImageUtils {
}
}
//事故图标
File srcImgFile = new File(templatePath + "/jinzhi.png");//得到文件
File srcImgFile = new File(templatePath + "/shigu.png");//得到文件
Image jinzhi = ImageIO.read(srcImgFile);//文件转化为图片
g.drawImage(jinzhi,534,17,30,30,null);
g.dispose();
@ -158,6 +169,33 @@ public class BoardImageUtils {
return AjaxResult.success(filePath);
}
/**
* 纯文字
* 固定格式
*
* @param textList 文字列表
* @return 情报板内容
*/
public static AjaxResult writeText(List<String> textList) {
List<Map<String,Object>> contentList = new ArrayList<>();
for (String text : textList) {
Map<String,Object> content = new HashMap<>();
content.put("ACTION","0");
content.put("COLOR","ffff00");
content.put("CONTENT",text);
content.put("FONT","1");
content.put("SPEED","0");
content.put("STAY","50");
content.put("formatStyle","2");
content.put("height","64");
content.put("width","768");
contentList.add(content);
}
return AjaxResult.success(contentList);
}
/**
* main方法:
@ -167,7 +205,7 @@ public class BoardImageUtils {
//获取数据集合;
/*ArrayList<ImageDTO> list = new ArrayList<>();
ArrayList<ImageDTO> list = new ArrayList<>();
list.add(ImageDTO.createRectImageDTO(new Color(0,255,0), 34, 26, 300,16));
list.add(ImageDTO.createRectImageDTO(new Color(255,255,0), 334, 26, 150,16));
@ -176,18 +214,19 @@ public class BoardImageUtils {
list.add(ImageDTO.createImageDTO("前方5公里发生事故缓行10分钟",new Color(255,0,0),new Font("Default", Font.BOLD, 22), 34, 0));
list.add(ImageDTO.createImageDTO("长清收费站约5分钟到达",new Color(255,255,255),new Font("Default", Font.BOLD, 12 ), 296, 51));
//事件场景
BoardImageUtils.writeEventImage(list);*/
BoardContentUtils.writeEventImage(list);
DcBoardImgLane boardImgLane = new DcBoardImgLane(BoardIconEnum.SPEED_LIMIT_120,BoardIconEnum.SPEED_LIMIT_120,BoardIconEnum.SPEED_LIMIT_100,BoardIconEnum.SPEED_LIMIT_100,BoardIconEnum.EMERGENCY_LANE);
//车道通行场景
BoardImageUtils.writeLaneImage(boardImgLane);
BoardContentUtils.writeLaneImage(boardImgLane);
boardImgLane = new DcBoardImgLane(BoardIconEnum.STRAIGHT_TRAVEL,BoardIconEnum.LEFT_DETOUR,BoardIconEnum.LANE_PROHIBITION,BoardIconEnum.RIGHT_DETOUR,BoardIconEnum.EMERGENCY_LANE);
//车道通行场景
BoardImageUtils.writeLaneImage(boardImgLane);
BoardContentUtils.writeLaneImage(boardImgLane);
//这句代码,自己项目中可以不用加,在这里防止main方法报错的;
System.exit(0);
}
Loading…
Cancel
Save