|
|
|
@ -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"); |
|
|
|
|