add checks on ImageUtils instances
[nikiroo-utils.git] / src / be / nikiroo / utils / android / ImageUtilsAndroid.java
index eb65ff135dd26bc4e7a659a04d48a4b8ea1a5985..4b3c1ea631d94689039b225925aff20e4ed57cc0 100644 (file)
@@ -7,6 +7,8 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import javax.imageio.ImageIO;
+
 import be.nikiroo.utils.Image;
 import be.nikiroo.utils.ImageUtils;
 import be.nikiroo.utils.StringUtils;
@@ -18,6 +20,14 @@ import be.nikiroo.utils.StringUtils;
  * @author niki
  */
 public class ImageUtilsAndroid extends ImageUtils {
+       @Override
+       protected boolean check() {
+               // If we can get the class, it means we have access to it
+               @SuppressWarnings("unused")
+               Object test = Bitmap.class;
+               return true;
+       }
+       
        @Override
        public void saveAsImage(Image img, File target, String format)
                        throws IOException {
@@ -62,8 +72,10 @@ public class ImageUtilsAndroid extends ImageUtils {
         *             in case of IO error
         */
        static public Bitmap fromImage(Image img) throws IOException {
-               int size = img.getData().length;
-               Bitmap image = BitmapFactory.decodeByteArray(img.getData(), 0, size);
+               byte[] array = img.getData();
+               int size = array.length;
+               // TODO: check if we can use a stream, too
+               Bitmap image = BitmapFactory.decodeByteArray(array, 0, size);
                if (image == null) {
                        String ssize = StringUtils.formatNumber(size);
                        throw new IOException(