修改了资源路径1
This commit is contained in:
parent
5c6718b905
commit
a8c9f2126c
@ -18,6 +18,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
@Service
|
||||
public class CertService {
|
||||
@ -34,7 +35,7 @@ public class CertService {
|
||||
){
|
||||
try {
|
||||
// 加载背景模板图片
|
||||
BufferedImage background = ImageIO.read(new File("static/cert/template.png"));
|
||||
BufferedImage background = ImageIO.read(new ClassPathResource("static/cert/template.png").getInputStream());
|
||||
|
||||
Graphics2D g2d = (Graphics2D) background.getGraphics();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
@ -1,19 +1,22 @@
|
||||
package com.example.caseData.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ImageUtil {
|
||||
public static byte[] readImageToBytes(String imagePath) throws IOException {
|
||||
File file = new File(imagePath);
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
byte[] bytes = new byte[(int) file.length()];
|
||||
int read = fis.read(bytes);
|
||||
if (read != bytes.length) {
|
||||
throw new IOException("读取文件长度不一致");
|
||||
ClassPathResource resource = new ClassPathResource(imagePath);
|
||||
try (InputStream inputStream = resource.getInputStream();
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
return bytes;
|
||||
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user