Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode a part of Bitmap from file in Android

I have a file with a very large image: for example 9000x9000.

I can't load the Bitmap in memory because the heap size. But I only need to display a small part of this bitmap for example the rect width=100-200 and height =200-400 (resulting size of the sub-bitmap =100x200)

How can I retrieve this bitmap from the file?

Note: I dont want to lose quality in the 100x200 image

Thanks

like image 210
Addev Avatar asked May 18 '12 11:05

Addev


2 Answers

is it possible that there is a solution for this?

for example , BitmapRegionDecoder .

It should work for API10 and above...

Usage:

BitmapRegionDecoder.newInstance(...).decodeRegion(...)
like image 198
android developer Avatar answered Oct 17 '22 07:10

android developer


It can easily be done using RapidDecoder.

I actually generated a 9000x9000 png which its file size is about 80MB and the 200x400 sized region was successfully loaded.

import rapid.decoder.BitmapDecoder;

Bitmap bitmap = BitmapDecoder.from("big-image.png")
                             .region(145, 192, 145 + 200, 192 + 400)
                             .decode();
imageView.setImageBitmap(bitmap);

It works for Android 2.2 and above.

like image 27
suckgamony Avatar answered Oct 17 '22 08:10

suckgamony