
Loading only the required size for display makes sense. Therefore loading all one million pixels is not required. The one million pixel image is only using 230,400 pixels on the larger screen, and 102,400 pixels on the smaller screen. One with 480x800 screen, and another with a 320×480 screen. A 1000×1000 placeholder image was loaded into an ImageView and the app run on two devices.
ANDROID STUDIO BITMAP ANDROID
Here’s an example of loading large bitmaps on different Android devices. This saves precious app memory and reduces the possibility of out of memory errors. Using a technique called subsampling the huge photo image being viewed on the Android device only consumes as much memory as required to display it, 2 MP for a HD resolution screen. The Nexus 5 phone has a HD screen (1920×1080), so why load more than 2 MP of data if the screen can only display a maximum of 2 MP. What about an 18 MP image? A massive 5184×3456. A 5 MP image can have a resolution of 2560×1920, that is greater than high definition (HD) television at 1920×1080, and bigger than the resolution of the Goggle Nexus 10 tablet device at 2560×1600. High end cameras can produce 20 MP or higher images. The file storing the image, usually a JPEG file, is smaller than the displayed image because of compression.
ANDROID STUDIO BITMAP CODE
The code for the Bitmap Loading demo project used in this article is available for importing into Android Studio.) Bitmaps can be BIG but Android Screens can be SmallĪ digital image from a camera on an Android voice can vary in size, between 5 and 18 megapixels (MP) is possible (and larger). When entering code in Studio add import statements when prompted by pressing Alt-Enter. The example code can be changed to meet your own requirements. This article assumes that the latest Android Studio is installed, a basic app can be created and run, here called Bitmap Loading, and the code in this article can be correctly copied into Android Studio. (For this Android tutorial try the code in a simple app.

The Options settings passed to the class can reduce the size of the bitmap, saving on memory usage. Android bitmap loading is achieved via the BitmapFactory class. Instead of loading the whole bitmap a reduced resolution version is loaded (via a technique called subsampling). Load a Bitmap from Resources Correctlyĭespite Android not dealing with multi-megabyte bitmap loading automatically, it can still be done. This occurs because Android was design for mobile devices, which may have limited hardware resources, including memory, and bitmaps can require large amounts of memory.

This usually occurs when the bitmaps are large (several megabytes uncompressed), also when running the code on older devices, or trying to load lots of bitmaps. When handling bitmaps Android developers can come across the error : bitmap size exceeds VM budget. Android Bitmap Loading for Efficient Memory Usage
