You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

944 lines
41 KiB

4 months ago
package com.parkingLot.quartz;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.parkingLot.dto.AreaInfoDTO;
import com.parkingLot.dto.DataDTO;
import com.parkingLot.dto.Response.CommonResponse;
import com.parkingLot.service.RemoteCallService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
*
*
* @author wu
* @since 2024/12/17 09:15
*/
@Slf4j
@Configuration
@EnableScheduling
public class QuartzImg {
@javax.annotation.Resource
private RemoteCallService remoteCallService;
private DataDTO dataDTO;
/**
*
*/
private void getAreaFreeSpaceNum() {
CommonResponse commonResponse = remoteCallService.GetAreaFreeSpaceNum();
Object data = commonResponse.getData();
if (data == null) {
return;
}
dataDTO = BeanUtil.copyProperties(data, DataDTO.class);
}
/**
* 91
*/
@Scheduled(cron = "0 */1 * * * *")
public void updateImgOne() {
getAreaFreeSpaceNum();
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.91_反面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 18);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[2];
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇南停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 133; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 2 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = height - 68;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.91输出反面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 91
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgTow() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.91_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 18);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[2];
;
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 133; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 2 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = height - 68;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.91输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 92
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgThree() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.92_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 18);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[2];
;
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 133; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 2 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = height - 68;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.92输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 93
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgFour() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.93_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 18);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[2];
;
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 133; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 2 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = height - 68;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.93输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 94
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgFive() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.94_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 18);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[2];
;
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇南停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 133; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 2 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = height - 68;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.94输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 95
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgSix() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.95_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 18);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[2];
;
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 133; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 2 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = height - 68;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.95输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 96
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgSeven() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.96_反面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 18);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[2];
;
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇南停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 133; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 2 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = height - 68;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.96输出反面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 96
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgEight() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.96_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 18);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[2];
;
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 133; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 2 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = height - 68;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.96输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 101
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgNine() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.101_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 50);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[3];
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[2] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇南停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 20; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 5 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = yPosition - 70;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.101输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 102
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgTen() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.102_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 50);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[3];
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[2] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇南停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 20; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 5 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = yPosition - 70;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.102输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 103
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgEleven() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.103_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 50);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[3];
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[2] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇南停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 20; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 5 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = yPosition - 70;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.103输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 104
*/
@Scheduled(cron = "2 */1 * * * *")
public void updateImgTwelve() {
try {
// 加载图片资源
Resource resource = new ClassPathResource("static/templates/192.168.1.104_正面.bmp");
InputStream inputStream = resource.getInputStream();
Image src = ImageIO.read(inputStream);
int width = src.getWidth(null);
int height = src.getHeight(null);
// 创建一个新的BufferedImage对象用于绘制
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
// 绘制原始图片
g.drawImage(src, 0, 0, width, height, null);
// 设置字体颜色
g.setColor(new Color(152, 251, 152)); // 设置字体颜色为淡绿色
// 设置加粗字体大小为18
Font font = new Font("黑体", Font.BOLD, 50);
g.setFont(font);
// 要绘制的字符串
String[] text = new String[3];
// 创建FontMetrics对象用于获取字符串的宽度
FontMetrics fm = g.getFontMetrics(font);
if (CollectionUtil.isEmpty(dataDTO.getAreaInfo())) {
return;
}
for (AreaInfoDTO dto : dataDTO.getAreaInfo()) {
if ("镇东停车场".equals(dto.getAreaName())) {
text[2] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇南停车场".equals(dto.getAreaName())) {
text[1] = String.valueOf(dto.getFreeSpaceNum());
}
if ("镇北停车场".equals(dto.getAreaName())) {
text[0] = String.valueOf(dto.getFreeSpaceNum());
}
}
// 设置初始y坐标
int yPosition = height - 20; // 初始y位置
// 循环绘制每个字符串,计算它们的宽度并进行右对齐
for (String str : text) {
int stringWidth = fm.stringWidth(str); // 计算字符串的宽度
// 计算绘制文本的x坐标使文本右对齐
int xPosition = width - 5 - stringWidth;
g.drawString(str, xPosition, yPosition); // 绘制字符串
// 调整y坐标确保文本不重叠
yPosition = yPosition - 70;
}
// 释放图形上下文
g.dispose();
// 输出文件路径
File out = new File("D:\\fujica\\PushScreenInfo\\192.168.1.104输出正面.bmp");
// 检查目标文件所在的目录是否存在
File parentDir = out.getParentFile();
if (!parentDir.exists()) {
// 如果目录不存在,创建该目录
parentDir.mkdirs();
}
// 保存修改后的图片
ImageIO.write(image, "bmp", out);
log.info("图片保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 91
*/
@Scheduled(cron = "5 */1 * * * *")
public void updateImgThirteen() {
try {
// 加载第一个图像
File file1 = new File("D:\\fujica\\PushScreenInfo\\192.168.1.91输出正面.bmp");
BufferedImage image1 = ImageIO.read(file1);
// 加载第二个图像
File file2 = new File("D:\\fujica\\PushScreenInfo\\192.168.1.91输出反面.bmp");
BufferedImage image2 = ImageIO.read(file2);
// 计算合并后图像的宽度和高度
int totalWidth = image1.getWidth() + image2.getWidth(); // 宽度是两个图像宽度之和
int maxHeight = Math.max(image1.getHeight(), image2.getHeight()); // 高度是两个图像中较大的高度
// 创建一个新的BufferedImage对象用于保存合并后的图像
BufferedImage mergedImage = new BufferedImage(totalWidth, maxHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = mergedImage.createGraphics();
// 绘制第一个图像到合并图像的左侧
g.drawImage(image1, 0, 0, null);
// 绘制第二个图像到合并图像的右侧
g.drawImage(image2, image1.getWidth(), 0, null);
// 释放图形上下文
g.dispose();
// 保存合并后的图像
File outFile = new File("D:\\fujica\\PushScreenInfo\\192.168.1.91输出正反.bmp");
ImageIO.write(mergedImage, "bmp", outFile);
log.info("图像合并并保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 96
*/
@Scheduled(cron = "5 */1 * * * *")
public void updateImgFourteen() {
try {
// 加载第一个图像
File file1 = new File("D:\\fujica\\PushScreenInfo\\192.168.1.96输出正面.bmp");
BufferedImage image1 = ImageIO.read(file1);
// 加载第二个图像
File file2 = new File("D:\\fujica\\PushScreenInfo\\192.168.1.96输出反面.bmp");
BufferedImage image2 = ImageIO.read(file2);
// 计算合并后图像的宽度和高度
int totalWidth = image1.getWidth() + image2.getWidth(); // 宽度是两个图像宽度之和
int maxHeight = Math.max(image1.getHeight(), image2.getHeight()); // 高度是两个图像中较大的高度
// 创建一个新的BufferedImage对象用于保存合并后的图像
BufferedImage mergedImage = new BufferedImage(totalWidth, maxHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = mergedImage.createGraphics();
// 绘制第一个图像到合并图像的左侧
g.drawImage(image1, 0, 0, null);
// 绘制第二个图像到合并图像的右侧
g.drawImage(image2, image1.getWidth(), 0, null);
// 释放图形上下文
g.dispose();
// 保存合并后的图像
File outFile = new File("D:\\fujica\\PushScreenInfo\\192.168.1.96输出正反.bmp");
ImageIO.write(mergedImage, "bmp", outFile);
log.info("图像合并并保存成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
}