Home | History | Annotate | Download | only in displaying-bitmaps
      1 page.title=Displaying Bitmaps Efficiently
      2 page.tags=bitmaps,images,graphics
      3 
      4 trainingnavtop=true
      5 startpage=true
      6 
      7 @jd:body
      8 
      9 <div id="tb-wrapper">
     10 <div id="tb">
     11 
     12 <h2>Dependencies and prerequisites</h2>
     13 <ul>
     14   <li>Android 2.1 (API Level 7) or higher</li>
     15   <li><a href="{@docRoot}tools/support-library/index.html">Support Library</a></li>
     16 </ul>
     17 
     18 <h2>Try it out</h2>
     19 
     20 <div class="download-box">
     21   <a href="{@docRoot}downloads/samples/DisplayingBitmaps.zip" class="button">Download the sample</a>
     22   <p class="filename">DisplayingBitmaps.zip</p>
     23 </div>
     24 
     25 </div>
     26 </div>
     27 
     28 <a class="notice-developers-video wide" href="http://www.youtube.com/watch?v=rsQet4nBVi8">
     29 <div>
     30     <h3>Video</h3>
     31     <p>DevBytes: Bitmap Allocation</p>
     32 </div>
     33 </a>
     34 
     35 <a class="notice-developers-video wide" href="http://www.youtube.com/watch?v=pMRnGDR6Cu0">
     36 <div>
     37     <h3>Video</h3>
     38     <p>DevBytes: Making Apps Beautiful - Part 4 - Performance Tuning</p>
     39 </div>
     40 </a>
     41 
     42 <p>Learn how to use common techniques to process and load {@link
     43 android.graphics.Bitmap} objects in a way that keeps your user interface (UI) components responsive
     44 and avoids exceeding your application memory limit. If you're not careful, bitmaps can quickly
     45 consume your available memory budget leading to an application crash due to the dreaded
     46 exception:<br />{@code java.lang.OutofMemoryError: bitmap size exceeds VM budget}.</p>
     47 
     48 <p>There are a number of reasons why loading bitmaps in your Android application is tricky:</p>
     49 
     50 <ul>
     51   <li>Mobile devices typically have constrained system resources. Android devices can have as little
     52   as 16MB of memory available to a single application. The <a
     53   href="http://source.android.com/compatibility/downloads.html">Android Compatibility Definition
     54   Document</a> (CDD), <i>Section 3.7. Virtual Machine Compatibility</i> gives the required minimum
     55   application memory for various screen sizes and densities. Applications should be optimized to
     56   perform under this minimum memory limit. However, keep in mind many devices are configured with
     57   higher limits.</li>
     58   <li>Bitmaps take up a lot of memory, especially for rich images like photographs. For example, the
     59   camera on the <a href="http://www.android.com/devices/detail/galaxy-nexus">Galaxy Nexus</a> takes 
     60   photos up to 2592x1936 pixels (5 megapixels). If the bitmap configuration used is {@link
     61   android.graphics.Bitmap.Config ARGB_8888} (the default from the Android 2.3 onward) then loading
     62   this image into memory takes about 19MB of memory (2592*1936*4 bytes), immediately exhausting the
     63   per-app limit on some devices.</li>
     64   <li>Android app UIs frequently require several bitmaps to be loaded at once. Components such as
     65   {@link android.widget.ListView}, {@link android.widget.GridView} and {@link
     66   android.support.v4.view.ViewPager} commonly include multiple bitmaps on-screen at once with many
     67   more potentially off-screen ready to show at the flick of a finger.</li>
     68 </ul>
     69 
     70 <h2>Lessons</h2>
     71 
     72 <dl>
     73   <dt><b><a href="load-bitmap.html">Loading Large Bitmaps Efficiently</a></b></dt>
     74     <dd>This lesson walks you through decoding large bitmaps without exceeding the per application
     75     memory limit.</dd>
     76 
     77   <dt><b><a href="process-bitmap.html">Processing Bitmaps Off the UI Thread</a></b></dt>
     78     <dd>Bitmap processing (resizing, downloading from a remote source, etc.) should never take place
     79     on the main UI thread. This lesson walks you through processing bitmaps in a background thread
     80     using {@link android.os.AsyncTask} and explains how to handle concurrency issues.</dd>
     81 
     82   <dt><b><a href="cache-bitmap.html">Caching Bitmaps</a></b></dt>
     83     <dd>This lesson walks you through using a memory and disk bitmap cache to improve the
     84     responsiveness and fluidity of your UI when loading multiple bitmaps.</dd>
     85 
     86   <dt><b><a href="manage-memory.html">Managing Bitmap Memory</a></b></dt>
     87     <dd>This lesson explains how to manage bitmap memory to maximize your app's performance.</dd>
     88 
     89   <dt><b><a href="display-bitmap.html">Displaying Bitmaps in Your UI</a></b></dt>
     90     <dd>This lesson brings everything together, showing you how to load multiple bitmaps into
     91     components like {@link android.support.v4.view.ViewPager} and {@link android.widget.GridView}
     92     using a background thread and bitmap cache.</dd>
     93 
     94 </dl>
     95