X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FImageUtilsAwt.java;h=4cf12c04cd0573629d90ed6e376be7c5ca6e7155;hb=505be508ae7d3fb48122be548b310a238cfb91eb;hp=6e9160f5c02f38964e343035d4cda7a7c7f34cff;hpb=7b42695f536a88cfc5fed57e98687394e3c42fe9;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/ui/ImageUtilsAwt.java b/src/be/nikiroo/utils/ui/ImageUtilsAwt.java index 6e9160f..4cf12c0 100644 --- a/src/be/nikiroo/utils/ui/ImageUtilsAwt.java +++ b/src/be/nikiroo/utils/ui/ImageUtilsAwt.java @@ -11,6 +11,7 @@ import javax.imageio.ImageIO; import be.nikiroo.utils.Image; import be.nikiroo.utils.ImageUtils; +import be.nikiroo.utils.StringUtils; /** * This class offer some utilities based around images and uses java.awt. @@ -18,6 +19,13 @@ import be.nikiroo.utils.ImageUtils; * @author niki */ public class ImageUtilsAwt extends ImageUtils { + @Override + protected boolean check() { + // Will not work if ImageIO is not available + ImageIO.getCacheDirectory(); + return true; + } + @Override public void saveAsImage(Image img, File target, String format) throws IOException { @@ -91,7 +99,19 @@ public class ImageUtilsAwt extends ImageUtils { } if (image == null) { - throw new IOException("Failed to convert input to image"); + String extra = ""; + if (img.getSize() <= 2048) { + try { + extra = ", content: " + + new String(img.getData(), "UTF-8"); + } catch (Exception e) { + extra = ", content unavailable"; + } + } + String ssize = StringUtils.formatNumber(img.getSize()); + throw new IOException( + "Failed to convert input to image, size was: " + ssize + + extra); } // Note: this code has been found on Internet;