]> source.dussan.org Git - poi.git/commitdiff
Avoid an exception when getting the default bitmap image size on some JVMs
authorNick Burch <nick@apache.org>
Mon, 13 Nov 2006 11:13:55 +0000 (11:13 +0000)
committerNick Burch <nick@apache.org>
Mon, 13 Nov 2006 11:13:55 +0000 (11:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@474253 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java

index f1b9b3a4df11e217278695b33db54c8ab94e96ae..3be79efbd19ab04437faf14720e3b1cebf801af1 100644 (file)
@@ -122,12 +122,19 @@ public class Picture extends SimpleShape {
     public void setDefaultSize(){\r
         PictureData pict = getPictureData();\r
         if (pict  instanceof Bitmap){\r
+            BufferedImage img = null;\r
             try {\r
-                BufferedImage img = ImageIO.read(new ByteArrayInputStream(pict.getData()));\r
-                if(img != null) setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));\r
-                else setAnchor(new java.awt.Rectangle(0, 0, 200, 200));\r
-            } catch (IOException e){\r
-                ;\r
+                       img = ImageIO.read(new ByteArrayInputStream(pict.getData()));\r
+            } \r
+            catch (IOException e){}\r
+               catch (NegativeArraySizeException ne) {}\r
+               \r
+            if(img != null) {\r
+               // Valid image, set anchor from it\r
+               setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));\r
+            } else {\r
+               // Invalid image, go with the default metafile size\r
+               setAnchor(new java.awt.Rectangle(0, 0, 200, 200));\r
             }\r
         } else {\r
             //default size of a metafile picture is 200x200 \r
index 6767a299b0920871da85deef119e6135370cc9c8..91f4f1f509860a2c4630d6961ddfb15d5ae482d2 100644 (file)
@@ -257,6 +257,11 @@ public class TestPictures extends TestCase{
 \r
         Slide slide = ppt.createSlide();\r
         File img = new File(cwd, "sci_cec.dib");\r
+        \r
+        // Check we can read the test DIB image\r
+        assertTrue(img.exists());\r
+        \r
+        // Add the image\r
         int idx = ppt.addPicture(img, Picture.DIB);\r
         Picture pict = new Picture(idx);\r
         assertEquals(idx, pict.getPictureIndex());\r