简化考试签名照片处理逻辑

dev
zhangyue 2026-03-09 08:59:35 +08:00
parent 3463ad5390
commit e70ac90cf4
1 changed files with 24 additions and 22 deletions

View File

@ -272,28 +272,30 @@ public class ArchivesQueryExe {
if (!ObjectUtils.isEmpty(params.getExamSignFlag())) { if (!ObjectUtils.isEmpty(params.getExamSignFlag())) {
String imageUrl = fileUrlConfig.getPrefixUrl() + params.getExamSignFaceUrl(); PictureRenderData examSignFacePicture = Pictures.ofUrl(fileUrlConfig.getPrefixUrl() + params.getExamSignFaceUrl(), PictureType.JPEG).size(100, 100).create();//网络图片地址
try (InputStream is = new URL(imageUrl).openStream()) { workItem.put("examSignFacePicture", examSignFacePicture);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); // String imageUrl = fileUrlConfig.getPrefixUrl() + params.getExamSignFaceUrl();
// try (InputStream is = new URL(imageUrl).openStream()) {
// Thumbnailator 自动处理 EXIF 方向,并缩放到 100x100保持比例 // ByteArrayOutputStream baos = new ByteArrayOutputStream();
Thumbnails.of(is) //
.keepAspectRatio(true) // 可选:保持比例,避免拉伸 // // Thumbnailator 自动处理 EXIF 方向,并缩放到 100x100保持比例
.outputFormat("JPEG") // Thumbnails.of(is)
.toOutputStream(baos); // .keepAspectRatio(true) // 可选:保持比例,避免拉伸
// .outputFormat("JPEG")
byte[] imageBytes = baos.toByteArray(); // .toOutputStream(baos);
ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes); //
PictureRenderData picture = Pictures.ofStream(bis) // byte[] imageBytes = baos.toByteArray();
.size(100, 100) // ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
.create(); // PictureRenderData picture = Pictures.ofStream(bis)
// .size(100, 100)
workItem.put("examSignFacePicture", picture); // .create();
} catch (Exception e) { //
e.printStackTrace(); // workItem.put("examSignFacePicture", picture);
// 可选:插入默认占位图 // } catch (Exception e) {
// workItem.put("examSignFacePicture", defaultPicture); // e.printStackTrace();
} // // 可选:插入默认占位图
// // workItem.put("examSignFacePicture", defaultPicture);
// }
} }
String templatePath = "templates/template/studyRecord.docx"; String templatePath = "templates/template/studyRecord.docx";