xiatian hai 1 ano
pai
achega
18f7b369c0

+ 50 - 0
src/main/java/cn/com/qmth/am/service/impl/StudentScoreServiceImpl.java

@@ -361,6 +361,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 		dto.setStudentId(score.getStudentId());
 		dto.setStudentScoreId(score.getId());
 		dto.setImage(getSlice(score, q, answerImages));
+//		saveSliceImage(score, dto.getImage());
 		try {
 			queue.put(dto);
 		} catch (InterruptedException e) {
@@ -396,6 +397,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 			String tem = url.split("\\?")[0];
 			String suff = tem.substring(tem.lastIndexOf(".") + 1).toLowerCase();
 			ret.setImage(ByteArray.fromUrl(url).value());
+//			saveSheetImage(score,pageIndex, ret.getImage());
 			ret.setPageIndex(pageIndex);
 			ret.setSuff(suff);
 			answerImages.put(pageIndex, ret);
@@ -404,6 +406,54 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
 			throw new RuntimeException(e);
 		}
 	}
+//	private void saveSheetImage(StudentScoreEntity s,Integer page,byte[] bs) {
+//		File dir=new File(sysProperty.getDataDir()+"/"+"sheet");
+//		if(!dir.exists()) {
+//			dir.mkdir();
+//		}
+//		File image=new File(dir.getAbsolutePath()+"/"+s.getStudentCode()+"-"+page+".jpg");
+//		if(image.exists()) {
+//			image.delete();
+//		}
+//		FileOutputStream out=null;
+//		try {
+//			out = new FileOutputStream(image);
+//			out.write(bs, 0, bs.length);
+//			out.flush();
+//		} catch (Exception e) {
+//		}finally {
+//			if(out!=null) {
+//				try {
+//					out.close();
+//				} catch (IOException e) {
+//				}
+//			}
+//		}
+//	}
+//	private void saveSliceImage(StudentScoreEntity s,byte[] bs) {
+//		File dir=new File(sysProperty.getDataDir()+"/"+"slice");
+//		if(!dir.exists()) {
+//			dir.mkdir();
+//		}
+//		File image=new File(dir.getAbsolutePath()+"/"+s.getStudentCode()+"-"+s.getMainNumber()+"-"+s.getSubNumber()+".jpg");
+//		if(image.exists()) {
+//			image.delete();
+//		}
+//		FileOutputStream out=null;
+//		try {
+//			out = new FileOutputStream(image);
+//			out.write(bs, 0, bs.length);
+//			out.flush();
+//		} catch (Exception e) {
+//		}finally {
+//			if(out!=null) {
+//				try {
+//					out.close();
+//				} catch (IOException e) {
+//				}
+//			}
+//		}
+//	}
 
 	private String getImageUrl(StudentScoreEntity score, QuestionEntity q, Integer pageIndex) {
 		if (DataType.MARKING_CLOUD.equals(sysProperty.getDataType())) {

+ 4 - 34
src/main/java/cn/com/qmth/am/utils/ImageUtil.java

@@ -211,38 +211,8 @@ public final class ImageUtil {
 		return null;
 	}
 
-	/**
-	 * 裁剪图片
-	 * 
-	 * @param img
-	 * @param dest
-	 * @param top
-	 * @param left
-	 * @param width
-	 * @param height
-	 * @return
-	 * @throws IOException
-	 */
-	public static boolean cutImage(File img, String dest, int top, int left, int width, int height) throws IOException {
-		File fileDest = new File(dest);
-		if (!fileDest.getParentFile().exists())
-			fileDest.getParentFile().mkdirs();
-		String ext = getExtension(dest).toLowerCase();
-		BufferedImage bi = (BufferedImage) ImageIO.read(img);
-		height = Math.min(height, bi.getHeight());
-		width = Math.min(width, bi.getWidth());
-		if (height <= 0)
-			height = bi.getHeight();
-		if (width <= 0)
-			width = bi.getWidth();
-		top = Math.min(Math.max(0, top), bi.getHeight() - height);
-		left = Math.min(Math.max(0, left), bi.getWidth() - width);
-
-		BufferedImage bi_cropper = bi.getSubimage(left, top, width, height);
-		return ImageIO.write(bi_cropper, ext.equals("png") ? "png" : "jpg", fileDest);
-	}
 
-	public static byte[] cutImage(byte[] img, String suff, int top, int left, int width, int height) {
+	public static byte[] cutImage(byte[] img, String suff, int x,int y, int width, int height) {
 		InputStream in = null;
 		BufferedImage bi = null;
 		ByteArrayOutputStream output = null;
@@ -255,10 +225,10 @@ public final class ImageUtil {
 				height = bi.getHeight();
 			if (width <= 0)
 				width = bi.getWidth();
-			top = Math.min(Math.max(0, top), bi.getHeight() - height);
-			left = Math.min(Math.max(0, left), bi.getWidth() - width);
+			x = Math.min(Math.max(0, x), bi.getWidth() - width);
+			y = Math.min(Math.max(0, y), bi.getHeight() - height);
 
-			BufferedImage bi_cropper = bi.getSubimage(left, top, width, height);
+			BufferedImage bi_cropper = bi.getSubimage(x, y, width, height);
 			output = new ByteArrayOutputStream();
 			ImageIO.write(bi_cropper, suff, output);
 			byte[] ret = output.toByteArray();