|
@ -2,6 +2,7 @@ package com.zc.business.utils; |
|
|
|
|
|
|
|
|
import com.ruoyi.common.config.RuoYiConfig; |
|
|
import com.ruoyi.common.config.RuoYiConfig; |
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
|
|
import com.ruoyi.common.utils.uuid.IdUtils; |
|
|
import com.zc.business.domain.DcBoardImgLane; |
|
|
import com.zc.business.domain.DcBoardImgLane; |
|
|
import com.zc.business.domain.ImageDTO; |
|
|
import com.zc.business.domain.ImageDTO; |
|
|
import com.zc.business.enums.BoardIconEnum; |
|
|
import com.zc.business.enums.BoardIconEnum; |
|
@ -36,6 +37,10 @@ public class BoardContentUtils { |
|
|
// private static final String templatePath = "D:\\ruoyi\\uploadPath\\boardTemplate";
|
|
|
// private static final String templatePath = "D:\\ruoyi\\uploadPath\\boardTemplate";
|
|
|
private static final String templatePath = RuoYiConfig.getBoardPath(); |
|
|
private static final String templatePath = RuoYiConfig.getBoardPath(); |
|
|
|
|
|
|
|
|
|
|
|
//保存地址
|
|
|
|
|
|
// private static final String imgPath = "D:\\ruoyi\\uploadPath\\boardImg";
|
|
|
|
|
|
private static final String imgPath = RuoYiConfig.getBoardPath(); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 事件场景 |
|
|
* 事件场景 |
|
|
* |
|
|
* |
|
@ -43,8 +48,7 @@ public class BoardContentUtils { |
|
|
*/ |
|
|
*/ |
|
|
public static AjaxResult writeEventImage(List<ImageDTO> list) { |
|
|
public static AjaxResult writeEventImage(List<ImageDTO> list) { |
|
|
|
|
|
|
|
|
// String filePath = RuoYiConfig.getBoardPath() + "/boardImg.png";
|
|
|
String filePath = imgPath + "/" + IdUtils.fastSimpleUUID() + ".png"; |
|
|
String filePath = "C:/Users/Lenovo/Desktop/event.png"; |
|
|
|
|
|
|
|
|
|
|
|
FileOutputStream outImgStream = null; |
|
|
FileOutputStream outImgStream = null; |
|
|
try { |
|
|
try { |
|
@ -55,15 +59,6 @@ public class BoardContentUtils { |
|
|
//背景颜色
|
|
|
//背景颜色
|
|
|
g.setBackground(Color.BLACK); |
|
|
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) { |
|
|
for (ImageDTO imgDTO : list) { |
|
|
if (imgDTO.getType() == 0) { |
|
|
if (imgDTO.getType() == 0) { |
|
@ -80,7 +75,7 @@ public class BoardContentUtils { |
|
|
//事故图标
|
|
|
//事故图标
|
|
|
File srcImgFile = new File(templatePath + "/shigu.png");//得到文件
|
|
|
File srcImgFile = new File(templatePath + "/shigu.png");//得到文件
|
|
|
Image jinzhi = ImageIO.read(srcImgFile);//文件转化为图片
|
|
|
Image jinzhi = ImageIO.read(srcImgFile);//文件转化为图片
|
|
|
g.drawImage(jinzhi,534,17,30,30,null); |
|
|
g.drawImage(jinzhi,544,7,50,50,null); |
|
|
g.dispose(); |
|
|
g.dispose(); |
|
|
|
|
|
|
|
|
// 输出图片
|
|
|
// 输出图片
|
|
@ -111,7 +106,7 @@ public class BoardContentUtils { |
|
|
public static AjaxResult writeLaneImage(DcBoardImgLane dcBoardImgLane) { |
|
|
public static AjaxResult writeLaneImage(DcBoardImgLane dcBoardImgLane) { |
|
|
|
|
|
|
|
|
// String filePath = RuoYiConfig.getBoardPath() + "/boardImg.png";
|
|
|
// String filePath = RuoYiConfig.getBoardPath() + "/boardImg.png";
|
|
|
String filePath = "C:/Users/Lenovo/Desktop/lane.png"; |
|
|
String filePath = imgPath + "/" + IdUtils.fastSimpleUUID() + ".png"; |
|
|
|
|
|
|
|
|
FileOutputStream outImgStream = null; |
|
|
FileOutputStream outImgStream = null; |
|
|
try { |
|
|
try { |
|
@ -124,30 +119,127 @@ public class BoardContentUtils { |
|
|
|
|
|
|
|
|
//分割线图标
|
|
|
//分割线图标
|
|
|
Image fenge = ImageIO.read(new File(templatePath + "/fenge.png"));//文件转化为图片
|
|
|
Image fenge = ImageIO.read(new File(templatePath + "/fenge.png"));//文件转化为图片
|
|
|
g.drawImage(fenge,150,4,8,56,null); |
|
|
g.drawImage(fenge,152,4,4,56,null); |
|
|
g.drawImage(fenge,304,4,8,56,null); |
|
|
g.drawImage(fenge,306,4,4,56,null); |
|
|
g.drawImage(fenge,458,4,8,56,null); |
|
|
g.drawImage(fenge,460,4,4,56,null); |
|
|
g.drawImage(fenge,612,4,8,56,null); |
|
|
g.drawImage(fenge,614,4,4,56,null); |
|
|
|
|
|
|
|
|
//第一车道
|
|
|
//第一车道
|
|
|
Image icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getFirstLane().getFilePath())); |
|
|
Image icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getFirstLane().getFilePath())); |
|
|
g.drawImage(icon,49,4,56,56,null); |
|
|
g.drawImage(icon,52,7,50,50,null); |
|
|
|
|
|
|
|
|
//第二车道
|
|
|
//第二车道
|
|
|
icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getSecondLane().getFilePath())); |
|
|
icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getSecondLane().getFilePath())); |
|
|
g.drawImage(icon,203,4,56,56,null); |
|
|
g.drawImage(icon,206,7,50,50,null); |
|
|
|
|
|
|
|
|
//第三车道
|
|
|
//第三车道
|
|
|
icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getThirdLane().getFilePath())); |
|
|
icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getThirdLane().getFilePath())); |
|
|
g.drawImage(icon,357,4,56,56,null); |
|
|
g.drawImage(icon,360,7,50,50,null); |
|
|
|
|
|
|
|
|
//第四车道
|
|
|
//第四车道
|
|
|
icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getFourthLane().getFilePath())); |
|
|
icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getFourthLane().getFilePath())); |
|
|
g.drawImage(icon,511,4,56,56,null); |
|
|
g.drawImage(icon,514,7,50,50,null); |
|
|
|
|
|
|
|
|
//应急车道
|
|
|
//应急车道
|
|
|
icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getEmergencyLane().getFilePath())); |
|
|
icon = ImageIO.read(new File(templatePath + dcBoardImgLane.getEmergencyLane().getFilePath())); |
|
|
g.drawImage(icon,665,4,56,56,null); |
|
|
g.drawImage(icon,668,7,50,50,null); |
|
|
|
|
|
|
|
|
|
|
|
g.dispose(); |
|
|
|
|
|
|
|
|
|
|
|
// 输出图片
|
|
|
|
|
|
outImgStream = new FileOutputStream(filePath); |
|
|
|
|
|
ImageIO.write(bufImg, "jpg", outImgStream); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("==== 系统异常::{} ====",e); |
|
|
|
|
|
} finally { |
|
|
|
|
|
try { |
|
|
|
|
|
if (null != outImgStream){ |
|
|
|
|
|
outImgStream.flush(); |
|
|
|
|
|
outImgStream.close(); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return AjaxResult.success(filePath); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 服务设施场景 |
|
|
|
|
|
* |
|
|
|
|
|
* @param |
|
|
|
|
|
*/ |
|
|
|
|
|
public static AjaxResult writeFacilitiesImage() { |
|
|
|
|
|
|
|
|
|
|
|
// String filePath = RuoYiConfig.getBoardPath() + "/boardImg.png";
|
|
|
|
|
|
String filePath = imgPath + "/" + IdUtils.fastSimpleUUID() + ".png"; |
|
|
|
|
|
|
|
|
|
|
|
FileOutputStream outImgStream = null; |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
//创建图片
|
|
|
|
|
|
BufferedImage bufImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
|
|
|
|
|
Graphics2D g = bufImg.createGraphics(); |
|
|
|
|
|
//背景颜色
|
|
|
|
|
|
g.setBackground(Color.BLACK); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//44
|
|
|
|
|
|
// 2
|
|
|
|
|
|
// 25
|
|
|
|
|
|
// 15
|
|
|
|
|
|
// 2
|
|
|
|
|
|
//20
|
|
|
|
|
|
|
|
|
|
|
|
//汽车图标
|
|
|
|
|
|
Image icon = ImageIO.read(new File(templatePath + "/car.png")); |
|
|
|
|
|
g.drawImage(icon,34,4,35,20,null); |
|
|
|
|
|
ImageDTO imgDTO = ImageDTO.createImageDTO("ETC",new Color(255,255,0),new Font("Default", Font.BOLD, 14), 40, 25); |
|
|
|
|
|
g.setColor(imgDTO.getColor()); //根据图片的背景设置水印颜色
|
|
|
|
|
|
g.setFont(imgDTO.getFont()); //设置字体
|
|
|
|
|
|
g.drawString(imgDTO.getText(), imgDTO.getX(), imgDTO.getY()); //画出水印
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//收费图标
|
|
|
|
|
|
icon = ImageIO.read(new File(templatePath + "/shoufei.png")); |
|
|
|
|
|
g.drawImage(icon,70,2,33,40,null); |
|
|
|
|
|
|
|
|
|
|
|
imgDTO = ImageDTO.createImageDTO("长清大学城收费站",new Color(255,255,0),new Font("Default", Font.BOLD, 20), 105, 2); |
|
|
|
|
|
g.setColor(imgDTO.getColor()); //根据图片的背景设置水印颜色
|
|
|
|
|
|
g.setFont(imgDTO.getFont()); //设置字体
|
|
|
|
|
|
g.drawString(imgDTO.getText(), imgDTO.getX(), imgDTO.getY()); //画出水印
|
|
|
|
|
|
|
|
|
|
|
|
imgDTO = ImageDTO.createImageDTO("14.7KM 10分钟",new Color(255,255,0),new Font("Default", Font.BOLD, 20), 105, 22); |
|
|
|
|
|
g.setColor(imgDTO.getColor()); //根据图片的背景设置水印颜色
|
|
|
|
|
|
g.setFont(imgDTO.getFont()); //设置字体
|
|
|
|
|
|
g.drawString(imgDTO.getText(), imgDTO.getX(), imgDTO.getY()); //画出水印
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//停车图标
|
|
|
|
|
|
icon = ImageIO.read(new File(templatePath + "/tingche.png")); |
|
|
|
|
|
g.drawImage(icon,384,6,28,33,null); |
|
|
|
|
|
//加油图标
|
|
|
|
|
|
icon = ImageIO.read(new File(templatePath + "/jiayou.png")); |
|
|
|
|
|
g.drawImage(icon,412,2,35,40,null); |
|
|
|
|
|
//餐厅图标
|
|
|
|
|
|
icon = ImageIO.read(new File(templatePath + "/canting.png")); |
|
|
|
|
|
g.drawImage(icon,447,6,33,33,null); |
|
|
|
|
|
|
|
|
|
|
|
imgDTO = ImageDTO.createImageDTO("长清服务区",new Color(255,255,0),new Font("Default", Font.BOLD, 20), 485, 2); |
|
|
|
|
|
g.setColor(imgDTO.getColor()); //根据图片的背景设置水印颜色
|
|
|
|
|
|
g.setFont(imgDTO.getFont()); //设置字体
|
|
|
|
|
|
g.drawString(imgDTO.getText(), imgDTO.getX(), imgDTO.getY()); //画出水印
|
|
|
|
|
|
|
|
|
|
|
|
imgDTO = ImageDTO.createImageDTO("17.7KM 15分钟",new Color(255,255,0),new Font("Default", Font.BOLD, 20), 485, 22); |
|
|
|
|
|
g.setColor(imgDTO.getColor()); //根据图片的背景设置水印颜色
|
|
|
|
|
|
g.setFont(imgDTO.getFont()); //设置字体
|
|
|
|
|
|
g.drawString(imgDTO.getText(), imgDTO.getX(), imgDTO.getY()); //画出水印
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//路况
|
|
|
|
|
|
imgDTO = ImageDTO.createRectImageDTO(new Color(0,255,0), 34, 47, 700,13); |
|
|
|
|
|
g.setColor(imgDTO.getColor()); |
|
|
|
|
|
g.fillRect(imgDTO.getX(),imgDTO.getY(),imgDTO.getRectWidth(),imgDTO.getRectHeight()); |
|
|
|
|
|
|
|
|
g.dispose(); |
|
|
g.dispose(); |
|
|
|
|
|
|
|
@ -216,17 +308,21 @@ public class BoardContentUtils { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//事件场景
|
|
|
//事件场景
|
|
|
BoardContentUtils.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); |
|
|
// DcBoardImgLane boardImgLane = new DcBoardImgLane(BoardIconEnum.SPEED_LIMIT_120,BoardIconEnum.SPEED_LIMIT_120,BoardIconEnum.SPEED_LIMIT_100,BoardIconEnum.SPEED_LIMIT_80,BoardIconEnum.EMERGENCY_LANE);
|
|
|
//车道通行场景
|
|
|
|
|
|
BoardContentUtils.writeLaneImage(boardImgLane); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DcBoardImgLane boardImgLane = new DcBoardImgLane(BoardIconEnum.STRAIGHT_TRAVEL,BoardIconEnum.LEFT_DETOUR,BoardIconEnum.LANE_PROHIBITION,BoardIconEnum.RIGHT_DETOUR,BoardIconEnum.EMERGENCY_LANE);
|
|
|
|
|
|
|
|
|
boardImgLane = new DcBoardImgLane(BoardIconEnum.STRAIGHT_TRAVEL,BoardIconEnum.LEFT_DETOUR,BoardIconEnum.LANE_PROHIBITION,BoardIconEnum.RIGHT_DETOUR,BoardIconEnum.EMERGENCY_LANE); |
|
|
|
|
|
//车道通行场景
|
|
|
//车道通行场景
|
|
|
BoardContentUtils.writeLaneImage(boardImgLane); |
|
|
// BoardContentUtils.writeLaneImage(boardImgLane);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//服务设施场景
|
|
|
|
|
|
BoardContentUtils.writeFacilitiesImage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//这句代码,自己项目中可以不用加,在这里防止main方法报错的;
|
|
|
//这句代码,自己项目中可以不用加,在这里防止main方法报错的;
|
|
|
System.exit(0); |
|
|
System.exit(0); |
|
|
} |
|
|
} |
|
|