Announcement regarding discontinued maintenance in 2021:
In devices above Android 8.0, bitmaps store in native heaps. In the future, most devices will keep upgrading to new above 8.0, so this repo will be useless. This is why I have decided to stop maintaining it. I apologize to anyone who looks forward to updates.
The size of physical memory RAM has been increasing for a decade; the limitation of the Java heap exists, though. Furthermore, the camera is improved, and the size of the images that we need to operate keeps increasing. By the way, even though some brands or companies produce phones whose xmx has been modified, the limitations on those devices are still insufficient for immensely large images.
It is a fact that Android's JVMs such as Dalvik and ART accord with JVM standards. So that the Android JVM has a configuration with xmx.
In the README, I don't explain more about what xmx is. You can look into docs or websites for more about it.
Due to the limitation of Java heap for one application, while you operate large bitmaps, the device may throw OOM.
On the other hand, the native heap has no limitation. It is able to allocate reach physical size. So, operating images in the native heap can avoid OOM. In this repo, I bypass Bitmap. In case it bypasses bitmap, it will bypass the Java heap.
To sum up, the native heap is unlimited for every developer. This is why the repo works. All operations of images are in the native heap, which will completely avoid OOM.
click to expand
I have tried to allocate numerous memory in the native heap and don't execute free
. The allocated memory exceeds 1G, which didn't give rise to OOM.
Below a picture, I run adb shell dumpsys meminfo PACKAGENAME
to print that memory information.
-
rotate jpeg
-
compress jpeg
-
resize jpeg
-
compress png (2018.04.10)
- provide other algorithms about compression, may introduce
optipng
, which has been used in most services or applications.
- provide other algorithms about compression, may introduce
-
rotate png
-
resize png
-
before you run on the device, you need to put a
test.jpg
on external storage. -
After you start this app:
test.jpg ----------compress/rotate---------> test2.jpg