Solution 1 :
Managed to do it using this PNGJ library , written in pure Java so usable in android, and which allows to write PNG files line by line without loading the whole image into memory.
Problem :
I am trying to use a BitmapRegionDecoder to load parts of a large Bitmap image in Android but am stuck because the BMP file format is not supported(only JPG and PNG).
Is is possible to “transcode” a bitmap image into JPG or PNG (compression doesn’t really matter) without loading the entire image into memory?
Something like
FileOutputStream fos = new FileOutputStream(pngFile);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = bmpInputStream.read(buffer)) > 0) {
// Process bytes to PNG format
fos.write(buffer, 0, bytesRead);
}
Comments
Comment posted by Gabe Sechan
Why not convert before you put the file on the device (on your machine or on the server)?
Comment posted by tishu
That is not an option the file is picked at runtime by the user
Comment posted by Gabe Sechan
That doesn’t prevent you from pre-encoding it. You just encode all of his choices. Using actual bitmaps, especially for large images, is a really weird choice these days- the file size would be huge.
Comment posted by tishu
That doesn’t make any sense I cannot preencode a file a user picks from his phone at runtime
Comment posted by Gabe Sechan
How did he get the file on his device? Encode it then. It should never be on disk as an actual bitmap. Nothing does bitmap these days.