public void saveAsImage(Image img, File target, String format)
throws IOException {
try {
- BufferedImage image = ImageUtilsAwt.fromImage(img);
+ BufferedImage image = fromImage(img);
boolean ok = false;
try {
}
// Some formats are not reliable
- // Second change: PNG
+ // 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) {
* @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;
}
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");