Android Load higher resolution image from local drawable-nodpi and zoom

In one of the native application, we need to load the conference map layout which contains the building architecture. Image resolution is 4648*3504 (width 8* height) and file size is 563KB. I have placed it under "res/drawable-nodpi/" folder inorder not to scale the image on multiple device screen density.

We will load the layout image in normal view. Then user clicks on the map to zoom it and see the layout areas in detail. Once they reached maximum zoom level, we will allow user to mark their current location in the conference hall. (in the map , we will have showrooms and user can mark their location by clicking on the map).

For this, when i try to load the image, it shows outof memory error. So as per the instructions in the developer.android.com, i scaled the image according to available screen width and height, images loading with out any problem. But when i zoom the image, clarity of the layout is missing due to scaling the image to screen size.

At times i got "Bitmap too large to be uploaded into a texture" when loading large image directly in layout xml file.

Is there any alternative method to implement the above requirement. How to load high resolution image in Imageview. How does image gallery handles large size files which has high quality.

Any input or method of implementing it, will help me in great way.

Thanks in Advance,

Srinivasan

Answers


For the large image size OutOfMemory error always occur

Reason :

Virtual heap size / Heap size of your device, every device have a different VHS like :64 MB, 128 MB, 256 MB etc

And when your image is loading in your activity it will take memory size for accessing the image and if the image have large scale anf it'll cross the heap size limit.

App will be crash due to OutOfMemory Exception

Solution:

  1. Reduce the resolution 4648*3504 to less size(width*height) and increase the dpi for image, for the zooming purpose and it will run fine.

  2. android:largeHeap="true" in the manifest.xml

By this android:largeHeap="true" the heapsize will be goes to double.

Through this you can save the app from crashing.


Need Your Help

iPhone 4.0 OS writing to visible file in sandbox

iphone file directory document

I was working prior to 4.0 OS with my iPhone and and writing to media/DCIM/100APPLE. I could download these files using DiskAid. This was a perfect dev solution. My provider without asking upgra...

Linux, fat32 and etc/fstab

linux mount fstab fat

I mounted a FAT32 drive onto my Linux computer using the following terminal command: