//图片路径
String imgSrc = user.getResume().getUsertouxiang();
//图片后缀
String imgSuffix = imgSrc.substring(imgSrc.lastIndexOf(".") + 1).trim().toLowerCase();
int ptype = 0;
if("png".equalsIgnoreCase(imgSuffix)){
ptype = HSSFWorkbook.PICTURE_TYPE_PNG;
}else if("jpg".equalsIgnoreCase(imgSuffix) || "jpeg".equalsIgnoreCase(imgSuffix)){
ptype = HSSFWorkbook.PICTURE_TYPE_JPEG;
}else{
ptype = -1;
}
try {
bufferImg = ImageIO.read(new File(imgSrc));
ImageIO.write(bufferImg, imgSuffix, byteArrayOut);
//画图的顶级管理器,一个sheet只能获取一个
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
//anchor主要用于设置图片的属性
HSSFClientAnchor anchor = new HSSFClientAnchor(35, 40, 912, 220,(short) 11, 4, (short) 13, 9);
//插入图片
patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), ptype));
} catch (IOException e) {
e.printStackTrace();
}