+ /**
+ * Save the given resource as an image on disk using the default image
+ * format for content.
+ *
+ * @param image
+ * the resource
+ * @param target
+ * the target file
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public void saveAsImage(BufferedImage image, File target)
+ throws IOException {
+ try {
+ String format = Instance.getConfig()
+ .getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase();
+
+ boolean ok = false;
+ try {
+ ok = ImageIO.write(image, format, target);
+ } catch (IOException e) {
+ ok = false;
+ }
+
+ // Some formats are not reliable
+ // Second change: PNG
+ if (!ok && !format.equals("png")) {
+ ok = ImageIO.write(image, "png", target);
+ }
+
+ if (!ok) {
+ throw new IOException(
+ "Cannot find a writer for this image and format: "
+ + format);
+ }
+ } catch (IOException e) {
+ throw new IOException("Cannot write image to " + target, e);
+ }
+ }
+