Android, decoding of big bitmap without loosing quality/resolution and with good user experience

StackOverflow https://stackoverflow.com/questions/23512812

  •  16-07-2023
  •  | 
  •  

Question

I know that it's a popular question, but I didn't find a solution for my situation and I just want to get adviсes.

I have an image, for example 4000 x 3000 px (or a bit bigger) and if I try to decode it I got OutOfMemory error. Almost all solutions I found suppose using inSampleSize option during decoding which is calculated with some special logic before. It is described in the official android docs (Loading Large Bitmaps Efficiently).

But I'm looking for the approach when I will not lose quality and resolution of image and at the same time I will give good experience for user. So I thought about decoding of bitmap by parts, but there are a lot of discussions on the Internet which suggest that it's not possible to give user nice (smooth) experience with such approach (decoding image by part using current display bounds and scale settings would be slow).

I'm very interested in maximum image resolution and quality since my app is doing some measurements and it's very important to give user ability to work (scale, move, point) with the original resolution.

Could you please advise is it possible to make the second approach smooth enough to give user good experience or is there any other nice approaches for my situation?

Was it helpful?

Solution

If you really want to provide hight quality of image, smooth moving and etc ImageView and regular ways to do it with Android sdk will not help you. I recommend you to use OpenGL for your purpose, take a look at AndEngine, it is game engine, but you can use only some of it's methods for creating one screen with your big image. AndEngine is very simple to implement, just add it to your project as any other library.

Other option is to work with OpenGL without any engines with Android SDK: http://developer.android.com/guide/topics/graphics/opengl.html

Here is a simple algorithm of showing big texture (image) with OpenGL:

  1. Split your image to small images like 500x500 (if you want to support OpenGL 1, image should be power of two, like 512x512)
  2. Create your camera with the sizes you want (I suggest you should create it with screen sizes)
  3. Just draw all your small pictures in render() method
  4. For moving just move your camera.

P.S link to AndEngine - http://www.andengine.org/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top