/**
* 根据工单Id 查询该条工单所对应的峰图
* overriding
* @see org.deyi.sc.service.PcrProjectService#selectPic(javax.servlet.http.HttpServletRequest, java.lang.String)
* @author: wanght
* 2018-2-24 上午10:00:59
* @param req
* @param orderId
* @return
*
*/
public Object selectPic(HttpServletRequest req, String orderId) {
List<Map<String, Object>> picMap = new ArrayList<Map<String,Object>>();
Map<String,Object> pdata = new HashMap<String,Object>();
pdata.put("orderId", orderId);
//通过orderId查询序列峰图,封图
List<Map<String, Object>> maps = pdao.selectPic(pdata);
String path = picPath.getProperty("uploadPic");
for (Map<String, Object> map : maps) {
String pnameString = path+File.separator+map.get("pname");
map.put("pname","data:image/png;base64,"+new Base64().encodeToString(getBytes(pnameString)) );
picMap.add(map);
}
pdata.put("rows", picMap);
return pdata;
}
/**
* 获得指定文件的byte数组
*/
private byte[] getBytes(String filePath){
byte[] buffer = null;
try {
File file = new File(filePath);
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
byte[] b = new byte[1000];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
fis.close();
bos.close();
buffer = bos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return buffer;
}
jsp 页面显示图片
最新推荐文章于 2020-11-22 10:38:46 发布