implementation of android.graphics.BitmapFactory (#460)

Only what was needed is implemented, compression method is still untested.
This commit is contained in:
Zero
2022-12-05 10:51:16 -05:00
committed by GitHub
parent 07314ef018
commit 0a748cd53b
3 changed files with 170 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
package android.graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class BitmapFactory {
public static Bitmap decodeStream(InputStream is) {
Bitmap bm = null;
try {
BufferedImage bf = ImageIO.read(is);
bm = new Bitmap(bf);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return bm;
}
public static Bitmap decodeByteArray(byte[] data, int offset, int length) {
Bitmap bm = null;
ByteArrayInputStream bais = new ByteArrayInputStream(data);
try {
BufferedImage bf = ImageIO.read(bais);
bm = new Bitmap(bf);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return bm;
}
}