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;