git://git.nikiroo.be
/
nikiroo-utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
943bdec
)
add checks on ImageUtils instances
author
Niki Roo
<niki@nikiroo.be>
Wed, 15 May 2019 19:39:59 +0000
(21:39 +0200)
committer
Niki Roo
<niki@nikiroo.be>
Wed, 15 May 2019 19:39:59 +0000
(21:39 +0200)
src/be/nikiroo/utils/ImageUtils.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/utils/android/ImageUtilsAndroid.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/utils/ui/ImageUtilsAwt.java
patch
|
blob
|
blame
|
history
diff --git
a/src/be/nikiroo/utils/ImageUtils.java
b/src/be/nikiroo/utils/ImageUtils.java
index cacff8d5bb3717696f633d2befaef893dbfbca4b..e95f73e4216d1cb8cc66db89227aca94fdd9c3f7 100644
(file)
--- a/
src/be/nikiroo/utils/ImageUtils.java
+++ b/
src/be/nikiroo/utils/ImageUtils.java
@@
-190,6
+190,14
@@
public abstract class ImageUtils {
return set_flag;
}
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}.
*
/**
* Create a new {@link ImageUtils}.
*
@@
-199,7
+207,10
@@
public abstract class ImageUtils {
for (String clazz : new String[] { "be.nikiroo.utils.ui.ImageUtilsAwt",
"be.nikiroo.utils.android.ImageUtilsAndroid" }) {
try {
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) {
}
}
} catch (Exception e) {
}
}
diff --git
a/src/be/nikiroo/utils/android/ImageUtilsAndroid.java
b/src/be/nikiroo/utils/android/ImageUtilsAndroid.java
index f198862437754f0883d6ecc77dbacf03c55d4eb7..4b3c1ea631d94689039b225925aff20e4ed57cc0 100644
(file)
--- a/
src/be/nikiroo/utils/android/ImageUtilsAndroid.java
+++ b/
src/be/nikiroo/utils/android/ImageUtilsAndroid.java
@@
-7,6
+7,8
@@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
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;
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 {
* @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 {
@Override
public void saveAsImage(Image img, File target, String format)
throws IOException {
@@
-64,6
+74,7
@@
public class ImageUtilsAndroid extends ImageUtils {
static public Bitmap fromImage(Image img) throws IOException {
byte[] array = img.getData();
int size = array.length;
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);
Bitmap image = BitmapFactory.decodeByteArray(array, 0, size);
if (image == null) {
String ssize = StringUtils.formatNumber(size);
diff --git
a/src/be/nikiroo/utils/ui/ImageUtilsAwt.java
b/src/be/nikiroo/utils/ui/ImageUtilsAwt.java
index 6e9160f5c02f38964e343035d4cda7a7c7f34cff..367e757a81ede843a9273f68cafbe6f816374297 100644
(file)
--- a/
src/be/nikiroo/utils/ui/ImageUtilsAwt.java
+++ b/
src/be/nikiroo/utils/ui/ImageUtilsAwt.java
@@
-18,6
+18,14
@@
import be.nikiroo.utils.ImageUtils;
* @author niki
*/
public class ImageUtilsAwt extends ImageUtils {
* @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 {
@Override
public void saveAsImage(Image img, File target, String format)
throws IOException {