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;
/**
* This class offer some utilities based around images and uses the Android
* @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 {
* in case of IO error
*/
static public Bitmap fromImage(Image img) throws IOException {
- Bitmap image = BitmapFactory.decodeByteArray(img.getData(), 0,
- img.getData().length);
+ 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) {
- int size = img.getData().length;
- String ssize = size + " byte";
- if (size > 1) {
- ssize = size + " bytes";
- if (size >= 1000) {
- size = size / 1000;
- ssize = size + " kb";
- if (size > 1000) {
- size = size / 1000;
- ssize = size + " MB";
- }
- }
- }
-
+ String ssize = StringUtils.formatNumber(size);
throw new IOException(
"Failed to convert input to image, size was: " + ssize);
}