Browse Source

fix: 修改抓拍失败时的兜底图

master
yinhuaiwei 1 month ago
parent
commit
47bd3a5cc7
2 changed files with 35 additions and 20 deletions
  1. +35
    -20
      inspect-ivs/src/main/java/com/inspect/ivs/service/IvsResourceRetryableDelegate.java
  2. BIN
      inspect-ivs/src/main/resources/images/ivs_error.jpg

+ 35
- 20
inspect-ivs/src/main/java/com/inspect/ivs/service/IvsResourceRetryableDelegate.java View File

@ -27,9 +27,6 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StreamUtils;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -282,28 +279,12 @@ public class IvsResourceRetryableDelegate {
}
public InputStream generateErrorImage() {
int width = 400, height = 200;
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufferedImage.createGraphics();
// 背景
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
// 字体
g.setColor(Color.RED);
g.setFont(new Font("Arial", Font.BOLD, 20));
g.drawString("Get Picture Fail", 120, 100);
g.dispose();
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", os);
byte[] bytes;
if (testMode) {
bytes = loadDefaultImage();
} else {
bytes = os.toByteArray();
bytes = loadErrorImage();
}
return new ByteArrayInputStream(bytes);
} catch (IOException e) {
@ -311,6 +292,40 @@ public class IvsResourceRetryableDelegate {
}
}
// public InputStream generateErrorImage() {
// int width = 400, height = 200;
// BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// Graphics2D g = bufferedImage.createGraphics();
//
// // 背景
// g.setColor(Color.WHITE);
// g.fillRect(0, 0, width, height);
//
// // 字体
// g.setColor(Color.RED);
// g.setFont(new Font("Arial", Font.BOLD, 20));
// g.drawString("Get Picture Fail", 120, 100);
// g.dispose();
//
// try {
// ByteArrayOutputStream os = new ByteArrayOutputStream();
// ImageIO.write(bufferedImage, "png", os);
// byte[] bytes;
// if (testMode) {
// bytes = loadDefaultImage();
// } else {
// bytes = os.toByteArray();
// }
// return new ByteArrayInputStream(bytes);
// } catch (IOException e) {
// throw new RuntimeException("生成错误图片失败", e);
// }
// }
public byte[] loadErrorImage() throws IOException {
ClassPathResource imgFile = new ClassPathResource("images/ivs_error.jpg");
return StreamUtils.copyToByteArray(imgFile.getInputStream());
}
public byte[] loadDefaultImage() throws IOException {
ClassPathResource imgFile = new ClassPathResource("images/ivs_default.jpg");


BIN
inspect-ivs/src/main/resources/images/ivs_error.jpg View File

Before After
Width: 1280  |  Height: 720  |  Size: 19 KiB

Loading…
Cancel
Save