Show bitmap of any size in Android

I want to display a bitmap read from an SD card in the actual pixel size on Android.

I can not assume anything about the bitmap, except Android, supports its image format. The bitmap can be huge.

It seems simple enough, but when you define restrictions on the use of Android memory, it becomes much more complicated.

Any ideas?

Change Trying to load a large bitmap produces an error from memory, because Android cannot allocate enough memory to decode it. You can download a smaller version of the bitmap, but this is not useful for displaying the bitmap at the actual pixel size. The question is how to show a large bitmap on Android, while staying within the applicationโ€™s memory limits (most likely by loading it in pieces).

Change 2 . The bitmap can be huge, but within reason. I'm talking about user images, not Nasa HD snapshots.

+4
source share
2 answers

Starting with android 2.3 (Gingerbread, API Level 10), you can use BitmapRegionDecoder . I do not know the solutions for older versions of Android. (and I was looking for it for my EmailAlbum app)

+1
source

Managed Code (Java) has 16/24 / 32MB memory limits, even if your device has much more free memory. I'm currently working on an application that needs to do this, and the solution is to distribute the bitmap in native code (NDK) and then render the image representations into a dedicated Java bitmap, which is the size of the screen. In your own code, you can allocate all available device memory, but for some reason the virtual machine limits it.

+3
source

Source: https://habr.com/ru/post/1314221/


All Articles