return set_flag;
}
+ /**
+ * Check that the class can operate (for instance, that all the required
+ * libraries or frameworks are present).
+ *
+ * @return TRUE if it works
+ */
+ abstract protected boolean check();
+
/**
* Create a new {@link ImageUtils}.
*
for (String clazz : new String[] { "be.nikiroo.utils.ui.ImageUtilsAwt",
"be.nikiroo.utils.android.ImageUtilsAndroid" }) {
try {
- return (ImageUtils) SerialUtils.createObject(clazz);
+ ImageUtils obj = (ImageUtils) SerialUtils.createObject(clazz);
+ if (obj.check()) {
+ return obj;
+ }
} catch (Exception e) {
}
}
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;
* @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 {
static public Bitmap fromImage(Image img) throws IOException {
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);
* @author niki
*/
public class ImageUtilsAwt extends ImageUtils {
+ @Override
+ protected boolean check() {
+ // If we can get the class, it means we have access to it
+ @SuppressWarnings("unused")
+ Object test = ImageIO.class;
+ return true;
+ }
+
@Override
public void saveAsImage(Image img, File target, String format)
throws IOException {