Version 4.4.1
[nikiroo-utils.git] / src / be / nikiroo / utils / ui / ImageUtilsAwt.java
index 26d14aaba2bf4ec30e30aac10992fa06efc9a468..148f8f57451141805c508de08e8254b0f3e2d407 100644 (file)
@@ -36,7 +36,14 @@ public class ImageUtilsAwt extends ImageUtils {
                        // Some formats are not reliable
                        // Second chance: PNG
                        if (!ok && !format.equals("png")) {
-                               ok = ImageIO.write(image, "png", target);
+                               try {
+                                       ok = ImageIO.write(image, "png", target);
+                               } catch (IllegalArgumentException e) {
+                                       throw e;
+                               } catch (Exception e) {
+                                       throw new IOException("Undocumented exception occured, "
+                                                       + "converting to IOException", e);
+                               }
                        }
 
                        if (!ok) {
@@ -61,7 +68,7 @@ public class ImageUtilsAwt extends ImageUtils {
         * @throws IOException
         *             in case of IO error
         */
-       static public BufferedImage fromImage(Image img) throws IOException {
+       public static BufferedImage fromImage(Image img) throws IOException {
                InputStream in = new ByteArrayInputStream(img.getData());
 
                int orientation;
@@ -73,7 +80,15 @@ public class ImageUtilsAwt extends ImageUtils {
                }
 
                in.reset();
-               BufferedImage image = ImageIO.read(in);
+               BufferedImage image;
+               try {
+                       image = ImageIO.read(in);
+               } catch (IllegalArgumentException e) {
+                       throw e;
+               } catch (Exception e) {
+                       throw new IOException("Undocumented exception occured, "
+                                       + "converting to IOException", e);
+               }
 
                if (image == null) {
                        throw new IOException("Failed to convert input to image");