Wednesday, February 3, 2016

Displaying Bitmaps Efficiently

Loading Large Bitmaps Efficiently
- Read Bitmap Dimensions and Type
    • BitmapFactory ( decodeByteArray(), decodeFile(), decodeResource(), etc.)
    • BitmapFactory.Options - Setting the inJustDecodeBounds property to true while decoding avoids memory allocation
- Load a Scaled Down Version into Memory
    • it’s not worth loading a higher pixel image into memory if it will eventually be displayed in a lower pixel thumbnail 
    • BitmapFactory.Options - use inSampleSize, To tell the decoder to subsample the image, loading a smaller version into memory
Processing Bitmaps Off the UI Thread
- Use an AsyncTask
        - Handle Concurrency ( when Bitmap is used in ListView, GridView )

Caching Bitmaps

  1. Use a Memory Cache ( fast-loading UI can use memory and disk cache to quickly reload processed images )
    • The LruCache class is well suited for Bitmap cacheing
    • Keeps recently referenced objects in a strong referenced LinkedHashMap
    • Evicts the least recently used member when cache memory exceeds its designated size.


Reference

1. developer.android.com
2. android-developers.blogspot ( Multithreading For Performance )

No comments:

Post a Comment