FileInputStream is = new FileInputStream(new File(cwd, "SimpleWithImages.xls"));
HSSFWorkbook wb = new HSSFWorkbook(is);
is.close();
List lst = wb.getAllPictures();
assertEquals(2, lst.size());
for (Iterator it = lst.iterator(); it.hasNext(); ) {
HSSFPictureData pict = (HSSFPictureData)it.next();
String ext = pict.suggestFileExtension();
byte[] data = pict.getData();
if (ext.equals("jpeg")){
//try to read image data using javax.imageio.* (JDK 1.4+)
BufferedImage jpg = ImageIO.read(new ByteArrayInputStream(data));
assertNotNull(jpg);
assertEquals(192, jpg.getWidth());
assertEquals(176, jpg.getHeight());
} else if (ext.equals("png")){
//try to read image data using javax.imageio.* (JDK 1.4+)
BufferedImage png = ImageIO.read(new ByteArrayInputStream(data));
assertNotNull(png);
assertEquals(300, png.getWidth());
assertEquals(300, png.getHeight());
} else {
fail("unexpected picture type: " + ext);
}
}