title: Image compression exception; Failed to allocate a 629749908 byte allocation with 16777216 free bytes and 142MB until OOM
body: <p>I have had some problems with the size of the images in my application, so I decided to compress the images, but I get the exception "Failed to allocate a 629749908 byte allocation with 16777216 free bytes and 142MB until OOM". I know that is a memory problem but, what I can do? there are other alternatives?</p>
  
  <p>This is the method I am using</p>
  
  <pre><code>private Bitmap checkCompression(Bitmap imageTarget) {
      double width = imageTarget.getWidth();//This has 2448
      double height = imageTarget.getHeight();//This has 3264
      double current = width * height;//Result is 7990272
      int reference = 1800000;
      double percentage = 0;
  
      if (current &gt; reference) {
          percentage = current / reference;
          return Bitmap.createScaledBitmap(imageTarget, (int) (width * percentage), (int) (height * percentage), true);
      }
  
      return imageTarget;
  }
  </code></pre>