title: Android Bitmap.createScaledBitmap throws java.lang.OutOfMemoryError mostly on Jelly Bean 4.1
body: <p>My app main purpose is to display images in following fashion as shown in image</p>
  
  <p><img src="https://i.stack.imgur.com/0aU4p.png" alt="enter image description here">  </p>
  
  <pre><code>private void setSelectedImage(int selectedImagePosition) 
  {
  
      BitmapDrawable bd = (BitmapDrawable) drawables.get(selectedImagePosition);
      Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.9), (int) (bd.getIntrinsicWidth() * 0.7), false);
      selectedImageView.setImageBitmap(b);
      selectedImageView.setScaleType(ScaleType.FIT_XY);
  
  }
  </code></pre>
  
  <p>Detailed code can be find <a href="http://www.mobisoftinfotech.com/wp-content/uploads/2012/06/galleryDemo.zip" rel="noreferrer">here</a></p>
  
  <p>exception is thrown at following line</p>
  
  <pre><code>Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.9), (int) (bd.getIntrinsicWidth() * 0.7), false);
  </code></pre>
  
  <p>Above function is called from <code>onItemSelected</code>. **The app still works well on 2.2 and 2.3, but throws exception immediately on 4.1 Above code works fine, but throws following exception. I didnot see any crashes in 2.2 and 2.3, but it immedidately crashes in 4.1 Is there any major difference of memory management in Jelly beans? **:</p>
  
  <pre><code>java.lang.OutOfMemoryError
  AndroidRuntime(2616):   at android.graphics.Bitmap.nativeCreate(Native Method)
  AndroidRuntime(2616):   at android.graphics.Bitmap.createBitmap(Bitmap.java:640)
  AndroidRuntime(2616):   at android.graphics.Bitmap.createBitmap(Bitmap.java:586) 
  AndroidRuntime(2616):   at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:466)
  AndroidRuntime(2616):   at com.rdx.gallery.GalleryDemoActivity.setSelectedImage(GalleryDemoActivity.java:183)
  </code></pre>