mirror of https://github.com/apache/poi.git
Avoid an exception when getting the default bitmap image size on some JVMs
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@474253 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a68c490e4b
commit
4954bbe0f1
|
@ -122,12 +122,19 @@ public class Picture extends SimpleShape {
|
|||
public void setDefaultSize(){
|
||||
PictureData pict = getPictureData();
|
||||
if (pict instanceof Bitmap){
|
||||
BufferedImage img = null;
|
||||
try {
|
||||
BufferedImage img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
|
||||
if(img != null) setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));
|
||||
else setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
|
||||
} catch (IOException e){
|
||||
;
|
||||
img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
|
||||
}
|
||||
catch (IOException e){}
|
||||
catch (NegativeArraySizeException ne) {}
|
||||
|
||||
if(img != null) {
|
||||
// Valid image, set anchor from it
|
||||
setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));
|
||||
} else {
|
||||
// Invalid image, go with the default metafile size
|
||||
setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
|
||||
}
|
||||
} else {
|
||||
//default size of a metafile picture is 200x200
|
||||
|
|
|
@ -257,6 +257,11 @@ public class TestPictures extends TestCase{
|
|||
|
||||
Slide slide = ppt.createSlide();
|
||||
File img = new File(cwd, "sci_cec.dib");
|
||||
|
||||
// Check we can read the test DIB image
|
||||
assertTrue(img.exists());
|
||||
|
||||
// Add the image
|
||||
int idx = ppt.addPicture(img, Picture.DIB);
|
||||
Picture pict = new Picture(idx);
|
||||
assertEquals(idx, pict.getPictureIndex());
|
||||
|
|
Loading…
Reference in New Issue