title: Working with bitmaps in separate threads
body: <p>I'm working in a project that opens an image, plays with it, and saves. The image can be a very huge image, like a camera pic, so I'm doing several things to ensure not getting OutOfMemory exceptions (basically what appears here <a href="http://developer.android.com/training/displaying-bitmaps/load-bitmap.html" rel="nofollow">http://developer.android.com/training/displaying-bitmaps/load-bitmap.html</a>):</p>
  
  <ul>
  <li>Perform all measurements of width and height of the image without actually open it, using:</li>
  </ul>
  
  
  
  <pre><code>BitmapFactory.Options options = new BitmapFactory.Options();
  options.inJustDecodeBounds = true;
  BitmapFactory.decodeFile(image_path, options);
  </code></pre>
  
  <ul>
  <li><p>Open images already resized ( <em>inSampleSize</em> ) and using <code>Bitmap.Config.RGB_565</code> (2B per pixel) besides <code>Bitmap.Config.ARGB_8888</code> (4B per pixel).</p></li>
  <li><p>Using temp files to not having a lot of bitmaps in memory (actually I only have one most of the cases, max 2 when applying masks or so).</p></li>
  <li><p>Recycling every bitmap after its use</p></li>
  <li><p>When showing the result in a <code>ImageView</code>, open it already scaled to the screen sizes.</p></li>
  </ul>
  
  <p>But, in some cases, when it's impossible to have only one bitmap loaded at a time to do a certain work (rotating the image, fine tune resizing, apply masks, ...), and mostly in medium range or old devices, I get an <em>OutOfMemory Exception</em>.</p>
  
  <p>I've started to add all the Image working in Background Jobs with something like the following (ok, I'm a newbie):</p>
  
  
  
  <pre><code>ProgressDialog dialog = ProgressDialog.show(this, null, "Please wait", true, false);
  new Thread(new BackgroundJob(this, new Runnable() {
      public void run() {
          ImageHelper.ImageManipulation(image_path); 
      }
  }, dialog, new Handler())).start();
  </code></pre>
  
  <p>I was hoping to get a completely memory free space with this new thread to perform there the Image manipulation tasks, but what I find is that the app crashes at same points for same reasons. Threads are created as a child process (ok) but sharing the max heap and the current used mem ...</p>
  
  <p>Is there a way to open a thread to perform image manipulation having more memory to work (freeing the memory used by the activity itself as it is another thread, for example)?</p>
  
  <p>Thank you very much.</p>