mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-07 21:04:34 -05:00
Basic android.graphics Rect and Canvas implementation (#461)
Some extensions use more Canvas methods, but they don't really seem to get that far yet, all the others I was able to test seem to work now.
This commit is contained in:
@@ -4,33 +4,48 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
public class BitmapFactory {
|
||||
public static Bitmap decodeStream(InputStream is) {
|
||||
Bitmap bm = null;
|
||||
public static Bitmap decodeStream(InputStream inputStream) {
|
||||
Bitmap bitmap = null;
|
||||
|
||||
try {
|
||||
BufferedImage bf = ImageIO.read(is);
|
||||
bm = new Bitmap(bf);
|
||||
ImageInputStream imageInputStream = ImageIO.createImageInputStream(inputStream);
|
||||
Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(imageInputStream);
|
||||
|
||||
if (!imageReaders.hasNext()) {
|
||||
throw new IllegalArgumentException("no reader for image");
|
||||
}
|
||||
|
||||
ImageReader imageReader = imageReaders.next();
|
||||
imageReader.setInput(imageInputStream);
|
||||
|
||||
BufferedImage image = imageReader.read(0, imageReader.getDefaultReadParam());
|
||||
bitmap = new Bitmap(image);
|
||||
|
||||
imageReader.dispose();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
return bm;
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static Bitmap decodeByteArray(byte[] data, int offset, int length) {
|
||||
Bitmap bm = null;
|
||||
Bitmap bitmap = null;
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||
ByteArrayInputStream byteArrayStream = new ByteArrayInputStream(data);
|
||||
try {
|
||||
BufferedImage bf = ImageIO.read(bais);
|
||||
bm = new Bitmap(bf);
|
||||
BufferedImage image = ImageIO.read(byteArrayStream);
|
||||
bitmap = new Bitmap(image);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
return bm;
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user