|
@@ -48,8 +48,6 @@ public class RotateTask implements Runnable {
|
|
String sliceMD5 = null;
|
|
String sliceMD5 = null;
|
|
LOGGER.info("准备生成缩略和裁切旋转图:{}", start);
|
|
LOGGER.info("准备生成缩略和裁切旋转图:{}", start);
|
|
if (imageConfig.isImageEnc()) {
|
|
if (imageConfig.isImageEnc()) {
|
|
- File thumbTempFile = null;
|
|
|
|
- File imageTempFile = null;
|
|
|
|
try {
|
|
try {
|
|
Student student = studentRepo.findByWorkIdAndExamNumber(paper.getWorkId(), paper.getExamNumber());
|
|
Student student = studentRepo.findByWorkIdAndExamNumber(paper.getWorkId(), paper.getExamNumber());
|
|
String imageMd5 = MD5Util.getImageRuleMd5(paper.getWorkId(), paper.getSubject().ordinal(), paper.getAreaCode(), paper.getExamNumber(), student.getId());
|
|
String imageMd5 = MD5Util.getImageRuleMd5(paper.getWorkId(), paper.getSubject().ordinal(), paper.getAreaCode(), paper.getExamNumber(), student.getId());
|
|
@@ -66,8 +64,8 @@ public class RotateTask implements Runnable {
|
|
String thumbOldPath = thumbPath + ".jpg";
|
|
String thumbOldPath = thumbPath + ".jpg";
|
|
String thumbTempPath = thumbPath + "temp.jpg";
|
|
String thumbTempPath = thumbPath + "temp.jpg";
|
|
File thumbOldFile = new File(thumbOldPath);
|
|
File thumbOldFile = new File(thumbOldPath);
|
|
- //读取指定路径下面的文件
|
|
|
|
- thumbTempFile = new File(thumbTempPath);
|
|
|
|
|
|
+ //读取原图
|
|
|
|
+ File thumbTempFile = new File(thumbTempPath);
|
|
InputStream is = new FileInputStream(thumbOldPath);
|
|
InputStream is = new FileInputStream(thumbOldPath);
|
|
OutputStream outputStream = new FileOutputStream(thumbTempPath);
|
|
OutputStream outputStream = new FileOutputStream(thumbTempPath);
|
|
SystemConstant.writeStream(is, outputStream);
|
|
SystemConstant.writeStream(is, outputStream);
|
|
@@ -75,74 +73,48 @@ public class RotateTask implements Runnable {
|
|
outputStream.flush();
|
|
outputStream.flush();
|
|
outputStream.close();
|
|
outputStream.close();
|
|
|
|
|
|
- //读取原图
|
|
|
|
- File thumbNewFile = new File(thumbNew + "_" + start + ".jpg");
|
|
|
|
- FileCopyUtils.copy(thumbTempFile, thumbNewFile);
|
|
|
|
|
|
+ //原图旋转
|
|
ImageCompression.rotate(thumbTempFile, thumbTempFile, degree);
|
|
ImageCompression.rotate(thumbTempFile, thumbTempFile, degree);
|
|
- FileCopyUtils.copy(thumbTempFile, thumbOldFile);
|
|
|
|
- InputStream is1 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(thumbNewFile));
|
|
|
|
- //加密原图
|
|
|
|
- OutputStream outputStream1 = new FileOutputStream(thumbNewFile);
|
|
|
|
|
|
+ thumbOldFile.renameTo(new File(thumbNew + "_" + start + ".jpg"));
|
|
|
|
+ thumbTempFile.renameTo(new File(thumbOldPath));
|
|
|
|
+ //加密旋转图
|
|
|
|
+ InputStream is1 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(thumbOldFile));
|
|
|
|
+ OutputStream outputStream1 = new FileOutputStream(thumbOldFile);
|
|
SystemConstant.writeStream(is1, outputStream1);
|
|
SystemConstant.writeStream(is1, outputStream1);
|
|
is1.close();
|
|
is1.close();
|
|
outputStream1.flush();
|
|
outputStream1.flush();
|
|
outputStream1.close();
|
|
outputStream1.close();
|
|
|
|
|
|
- //生成旋转图和加密
|
|
|
|
- InputStream is2 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(thumbOldFile));
|
|
|
|
- OutputStream outputStream2 = new FileOutputStream(thumbOldFile);
|
|
|
|
|
|
+ //裁切原图旋转生成
|
|
|
|
+ String imageOldPath = imagePath + ".jpg";
|
|
|
|
+ String imageTempPath = imagePath + "temp.jpg";
|
|
|
|
+ File imageOldFile = new File(imageOldPath);
|
|
|
|
+ //读取原图
|
|
|
|
+ File imageTempFile = new File(imageTempPath);
|
|
|
|
+ InputStream is2 = new FileInputStream(imageOldPath);
|
|
|
|
+ OutputStream outputStream2 = new FileOutputStream(imageTempFile);
|
|
SystemConstant.writeStream(is2, outputStream2);
|
|
SystemConstant.writeStream(is2, outputStream2);
|
|
is2.close();
|
|
is2.close();
|
|
outputStream2.flush();
|
|
outputStream2.flush();
|
|
outputStream2.close();
|
|
outputStream2.close();
|
|
|
|
|
|
- //裁切原图旋转生成
|
|
|
|
- String imageOldPath = imagePath + ".jpg";
|
|
|
|
- String imageTempPath = imagePath + "temp.jpg";
|
|
|
|
- File imageOldFile = new File(imageOldPath);
|
|
|
|
- //读取指定路径下面的文件
|
|
|
|
- imageTempFile = new File(imageTempPath);
|
|
|
|
- InputStream is3 = new FileInputStream(imageOldPath);
|
|
|
|
- OutputStream outputStream3 = new FileOutputStream(imageTempFile);
|
|
|
|
|
|
+ //原图旋转
|
|
|
|
+ ImageCompression.rotate(imageTempFile, imageTempFile, degree);
|
|
|
|
+ imageOldFile.renameTo(new File(imageNew + "_" + start + ".jpg"));
|
|
|
|
+ imageTempFile.renameTo(new File(imageOldPath));
|
|
|
|
+ //加密旋转图
|
|
|
|
+ InputStream is3 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(imageOldFile));
|
|
|
|
+ OutputStream outputStream3 = new FileOutputStream(imageOldFile);
|
|
SystemConstant.writeStream(is3, outputStream3);
|
|
SystemConstant.writeStream(is3, outputStream3);
|
|
is3.close();
|
|
is3.close();
|
|
outputStream3.flush();
|
|
outputStream3.flush();
|
|
outputStream3.close();
|
|
outputStream3.close();
|
|
|
|
|
|
- //读取原图
|
|
|
|
- File imageNewFile = new File(imageNew + "_" + start + ".jpg");
|
|
|
|
- FileCopyUtils.copy(imageTempFile, imageNewFile);
|
|
|
|
- ImageCompression.rotate(imageTempFile, imageTempFile, degree);
|
|
|
|
- FileCopyUtils.copy(imageTempFile, imageOldFile);
|
|
|
|
- InputStream is4 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(imageNewFile));
|
|
|
|
- //加密原图
|
|
|
|
- OutputStream outputStream4 = new FileOutputStream(imageNewFile);
|
|
|
|
- SystemConstant.writeStream(is4, outputStream4);
|
|
|
|
|
|
+ InputStream is4 = new FileInputStream(imageOldFile);
|
|
|
|
+ sliceMD5 = DigestUtils.md5Hex(is4);
|
|
is4.close();
|
|
is4.close();
|
|
- outputStream4.flush();
|
|
|
|
- outputStream4.close();
|
|
|
|
-
|
|
|
|
- //生成旋转图和加密
|
|
|
|
- InputStream is5 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(imageOldFile));
|
|
|
|
- OutputStream outputStream5 = new FileOutputStream(imageOldFile);
|
|
|
|
- SystemConstant.writeStream(is5, outputStream5);
|
|
|
|
- is5.close();
|
|
|
|
- outputStream5.flush();
|
|
|
|
- outputStream5.close();
|
|
|
|
-
|
|
|
|
- InputStream is6 = new FileInputStream(imageNewFile);
|
|
|
|
- sliceMD5 = DigestUtils.md5Hex(is6);
|
|
|
|
- is6.close();
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- } finally {
|
|
|
|
-// System.gc();
|
|
|
|
- if (Objects.nonNull(thumbTempFile) && thumbTempFile.exists()) {
|
|
|
|
- thumbTempFile.delete();
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(imageTempFile) && imageTempFile.exists()) {
|
|
|
|
- imageTempFile.delete();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
thumbPath = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
thumbPath = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|