修复打印预览图片是压缩图片显示不出来

master
zengwh 4 years ago
parent 41b616e6ea
commit e9034eb272

@ -15,6 +15,7 @@ import com.emr.vo.User;
import com.emr.vo.commomSearch.CommomVo;
import com.sun.media.jai.codec.*;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
@ -188,9 +189,9 @@ public class CommomService {
String srcStr = "";
if (StringUtils.isNotBlank(scanPageArr[i])) {
if ("1".equals(sourceArr[i])) {
srcStr = root1 + "\\" + scanPageArr[i];
srcStr = root1 + File.separator + scanPageArr[i];
} else {
srcStr = root2 + "\\" + scanPageArr[i];
srcStr = root2 + File.separator + scanPageArr[i];
}
}
src.add(srcStr);
@ -235,9 +236,9 @@ public class CommomService {
String srcStr = "";
if (StringUtils.isNotBlank(scanPageArr[i])) {
if ("1".equals(sourceArr[i])) {
srcStr = root1 + "\\" + scanPageArr[i];
srcStr = root1 + File.separator + scanPageArr[i];
} else {
srcStr = root2 + "\\" + scanPageArr[i];
srcStr = root2 + File.separator + scanPageArr[i];
}
}
src.add(srcStr);
@ -287,9 +288,9 @@ public class CommomService {
String srcStr = "";
if (StringUtils.isNotBlank(scanPageArr[i])) {
if ("1".equals(sourceArr[i])) {
srcStr = root1 + "\\" + scanPageArr[i];
srcStr = root1 + File.separator + scanPageArr[i];
} else {
srcStr = root2 + "\\" + scanPageArr[i];
srcStr = root2 + File.separator + scanPageArr[i];
}
}
src.add(srcStr);
@ -333,9 +334,9 @@ public class CommomService {
String srcStr = "";
if (StringUtils.isNotBlank(scanPageArr[i])) {
if ("1".equals(sourceArr[i])) {
srcStr = root1 + "\\" + scanPageArr[i];
srcStr = root1 + File.separator + scanPageArr[i];
} else {
srcStr = root2 + "\\" + scanPageArr[i];
srcStr = root2 + File.separator + scanPageArr[i];
}
}
src.add(srcStr);
@ -373,7 +374,7 @@ public class CommomService {
//判断图片名称是否存在,存在重命名
picName = getPicName(root, picName, pic);
//组织绝对路径
String src = root + "\\" + picName;
String src = root + File.separator + picName;
//上传图片
pic.transferTo(new File(src));
//设置进对象
@ -399,7 +400,7 @@ public class CommomService {
//D:\新图像\202005\GDZT20120916076-2a41fe252a024978af7098afcf52ca1a
//格式化年月
SimpleDateFormat fmt1 = new SimpleDateFormat("yyyyMM");
String path = newPicRoot + "\\" + fmt1.format(new Date()) + "\\" + inpatientId + "-" + patientId;
String path = newPicRoot + File.separator + fmt1.format(new Date()) + File.separator + inpatientId + "-" + patientId;
path = path.replaceAll(" ", "");
//该目录不存在,创建目录
if (!new File(path).isDirectory()) {
@ -411,7 +412,7 @@ public class CommomService {
//验证图片是否存在,存在重命名
private String getPicName(String root, String fullName, MultipartFile pic) {
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String src = root + "\\" + fullName;
String src = root + File.separator + fullName;
File file = new File(src);
//判断是否存在,存在文件加日期
if (file.exists()) {
@ -456,7 +457,7 @@ public class CommomService {
rootPath = rootPathList[1];
}
//原图片地址
String srcPath = rootPath + "\\" + nameList[i];
String srcPath = rootPath + File.separator + nameList[i];
//定义输出地址
String outSrc = "";
//获取项目上下文地址
@ -464,7 +465,7 @@ public class CommomService {
(printIsImg != null && printIsImg == 1)) {
//需要水印
//组织加水印后图片存放目录
String waterPicRoot = WATERPICPATH + patientId + "\\" + sourceList[i] + "\\";
String waterPicRoot = WATERPICPATH + patientId + File.separator + sourceList[i] + File.separator;
//目录不存在则创建
if (!new File(waterPicRoot).isDirectory()) {
new File(waterPicRoot).mkdirs();
@ -475,11 +476,11 @@ public class CommomService {
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath);
//组织输出地址
}
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + "\\" + sourceList[i] + "\\" + nameList[i];
outSrc = EMRRECORDJSP + File.separator + "reload" + File.separator + patientId + File.separator + sourceList[i] + File.separator + nameList[i];
/*if (srcPath.substring(srcPath.length() - 3).equals("tif")) {
//需要水印
//组织加水印后图片存放目录
String waterJpgRoot = WATERTIFTOJPGPATH + patientId + "\\" + sourceList[i] + "\\";
String waterJpgRoot = WATERTIFTOJPGPATH + patientId + File.separator + sourceList[i] + File.separator;
//目录不存在则创建
if (!new File(waterJpgRoot).isDirectory()) {
new File(waterJpgRoot).mkdirs();
@ -493,7 +494,7 @@ public class CommomService {
String waterPicPath = waterPicRoot + nameList[i].substring(0, nameList[i].lastIndexOf("."))+ ".jpg";
img2PdfUtil.addWatermarkPic1(new File(tifToJpgRoot), emrPdfWaterSet, waterPicPath);
}
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + "\\" + sourceList[i] + "\\" + nameList[i].substring(0, nameList[i].lastIndexOf("."))+ ".jpg";
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + File.separator + sourceList[i] + File.separator + nameList[i].substring(0, nameList[i].lastIndexOf("."))+ ".jpg";
} else {
//组织加水印后图片存放地址
String waterPicPath = waterPicRoot + nameList[i];
@ -501,17 +502,34 @@ public class CommomService {
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath);
//组织输出地址
}
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + "\\" + sourceList[i] + "\\" + nameList[i];
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + File.separator + sourceList[i] + File.separator + nameList[i];
}*/
} else {
//不需要水印
//将原图片地址转换成映射地址
//获取盘符并转换映射地址的头部地址
String root = selectRootByNotWater(srcPath);
//获取盘符后面的地址
String str1 = srcPath.substring(0, srcPath.indexOf("\\"));
String picPath = srcPath.substring(str1.length() + 1, srcPath.length());
outSrc = EMRRECORDJSP + "\\" + root + picPath;
String root = "";
String picPath = "";
//判断是否是tif图片
boolean tifFileFlag = checkTifFile(srcPath);
if(tifFileFlag){
String picSrc = WATERPICPATH + patientId + File.separator + sourceList[i] + File.separator;
//目录不存在则创建
if (!new File(picSrc).isDirectory()) {
new File(picSrc).mkdirs();
}
//组织加水印后图片存放地址
picPath = picSrc + nameList[i];
//转换图片输出
tifToJpg(srcPath,picPath);
outSrc = EMRRECORDJSP + File.separator + "reload" + File.separator + patientId + File.separator + sourceList[i] + File.separator + nameList[i];
}else{
//将原图片地址转换成映射地址
//获取盘符并转换映射地址的头部地址
root = selectRootByNotWater(srcPath);
//获取盘符后面的地址
String str1 = srcPath.substring(0, srcPath.indexOf(File.separator));
picPath = srcPath.substring(str1.length() + 1, srcPath.length());
outSrc = EMRRECORDJSP + File.separator + root + picPath;
}
}
outs.add(outSrc);
Integer value = Math.round((i + 1) * 100 / nameList.length);
@ -521,6 +539,31 @@ public class CommomService {
return outs;
}
/**
* tif
* @param srcPath
* @return
*/
private boolean checkTifFile(String srcPath) {
InputStream is = null;
try {
is = new FileInputStream(new File(srcPath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte[] content = new byte[0];
try {
content = IOUtils.toByteArray(is);
} catch (IOException e) {
e.printStackTrace();
}
// 判断图片类型jpg jpeg png bmp编码方式是tif格式的
if (content[0] == 0x49 && content[1] == 0x49 && content[2] == 0x2A && content[3] == 0x00) {
return true;
}
return false;
}
private static String tifToJpg(String tifUrl, String tifToJpgRoot) {
File fileTiff = new File(tifToJpgRoot);
if (fileTiff.exists()) {
@ -587,7 +630,7 @@ public class CommomService {
}
}
//原图片地址
String srcPath = rootPath + "\\" + nameList[i];
String srcPath = rootPath + File.separator + nameList[i];
//定义输出地址
String outSrc = "";
//获取项目上下文地址
@ -596,7 +639,7 @@ public class CommomService {
if (num == 1) {
//第二套打印图像输出
//组织加水印后图片存放目录
String waterPicRoot = WATERPICPATH + patientId + "\\" + 3 + "\\";
String waterPicRoot = WATERPICPATH + patientId + File.separator + 3 + File.separator;
//目录不存在则创建
if (!new File(waterPicRoot).isDirectory()) {
new File(waterPicRoot).mkdirs();
@ -607,10 +650,10 @@ public class CommomService {
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath);
}
//组织输出地址
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + "\\" + 3 + "\\" + nameList[i];
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + File.separator + 3 + File.separator + nameList[i];
} else {
//组织加水印后图片存放目录
String waterPicRoot = WATERPICPATH + patientId + "\\" + sourceList[i] + "\\";
String waterPicRoot = WATERPICPATH + patientId + File.separator + sourceList[i] + File.separator;
//目录不存在则创建
if (!new File(waterPicRoot).isDirectory()) {
new File(waterPicRoot).mkdirs();
@ -621,7 +664,7 @@ public class CommomService {
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath);
}
//组织输出地址
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + "\\" + sourceList[i] + "\\" + nameList[i];
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + File.separator + sourceList[i] + File.separator + nameList[i];
}
} else {
//不需要水印
@ -629,9 +672,9 @@ public class CommomService {
//获取盘符并转换映射地址的头部地址
String root = selectRootByNotWater(srcPath);
//获取盘符后面的地址
String str1 = srcPath.substring(0, srcPath.indexOf("\\"));
String str1 = srcPath.substring(0, srcPath.indexOf(File.separator));
String picPath = srcPath.substring(str1.length() + 1, srcPath.length());
outSrc = EMRRECORDJSP + "\\" + root + picPath;
outSrc = EMRRECORDJSP + File.separator + root + picPath;
}
outs.add(outSrc);
Integer value = Math.round((i + 1) * 100 / nameList.length);

@ -510,6 +510,8 @@ public class img2PdfUtil {
* @param filePath
* @return
*/
/*
public static String tiffTuanJPG(String filePath){
String format = filePath.substring(filePath.lastIndexOf(".")+1);
String turnJpgFile = filePath.replace("tiff", "jpg");
@ -525,7 +527,7 @@ public class img2PdfUtil {
ops = new FileOutputStream(turnJpgFile);
//文件存储输出流
JPEGEncodeParam param = new JPEGEncodeParam();
ImageEncoder image = ImageCodec.createImageEncoder("jpg", ops, param); //指定输出格式
ImageEncoder image = ImageCodec.createImageEncoder("JPEG", ops, param); //指定输出格式
image.encode(rd );
//解析输出流进行输出
ops.close();
@ -538,4 +540,5 @@ public class img2PdfUtil {
}
return turnJpgFile;
}
*/
}

Loading…
Cancel
Save