修改了资源路径1
This commit is contained in:
parent
5c6718b905
commit
a8c9f2126c
@ -18,6 +18,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CertService {
|
public class CertService {
|
||||||
@ -34,7 +35,7 @@ public class CertService {
|
|||||||
){
|
){
|
||||||
try {
|
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();
|
Graphics2D g2d = (Graphics2D) background.getGraphics();
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|||||||
@ -1,19 +1,22 @@
|
|||||||
package com.example.caseData.utils;
|
package com.example.caseData.utils;
|
||||||
|
|
||||||
import java.io.File;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
|
|
||||||
public class ImageUtil {
|
public class ImageUtil {
|
||||||
public static byte[] readImageToBytes(String imagePath) throws IOException {
|
public static byte[] readImageToBytes(String imagePath) throws IOException {
|
||||||
File file = new File(imagePath);
|
ClassPathResource resource = new ClassPathResource(imagePath);
|
||||||
try (FileInputStream fis = new FileInputStream(file)) {
|
try (InputStream inputStream = resource.getInputStream();
|
||||||
byte[] bytes = new byte[(int) file.length()];
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||||
int read = fis.read(bytes);
|
|
||||||
if (read != bytes.length) {
|
byte[] buffer = new byte[1024];
|
||||||
throw new IOException("读取文件长度不一致");
|
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