1.图片存储在数据库中,字段类型是blob。
2.
import java.awt.p_w_picpath.BufferedImage;
import java.io.ByteArrayOutputStream;
import org.hibernate.lob.SerializableBlob;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
SerializableBlob blob = (SerializableBlob)图片字段值;
HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,0,0,(short) 0,1,(short)1,6);
anchor.setAnchorType(2);
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
try {
BufferedImage bufferImg = ImageIO.read(blob.getBinaryStream()) ;
ImageIO.write(bufferImg,"jpg",byteArrayOut);
patriarch.createPicture(anchor , workBook.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
} catch (Exception e) {
e.printStackTrace();
}