-1

Am getting Exception error when loading images from assets to arraylist. this is the error in log cat: E/AndroidRuntime(2837): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Please some one help me with this,Thanks in advance

  • see my answer: http://stackoverflow.com/questions/10737582/bitmap-size-exceeds-vm-budget-error-android/10738115#10738115 – Shrikant Ballal Jul 07 '12 at 07:45
  • http://stackoverflow.com/questions/10255910/bitmap-memory-leaks/10255989#10255989 – mayank_droid Jul 07 '12 at 07:48
  • possible duplicate of [Android: Strange out of memory issue while loading an image to a Bitmap object](http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object) – Darshan Rivka Whittle Jul 07 '12 at 07:56

1 Answers1

0

Once, i tried to re-size the image, i' also having the same problem, i used the below code, you can modify as it yours,

public Bitmap custom_SizedImage(String intent_data2) {

        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(intent_data2, options);
        double sampleSize = 0;
        Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
                .abs(options.outWidth - targetWidth);

        if (options.outHeight * options.outWidth * 2 >= 1638) {
            sampleSize = scaleByHeight ? options.outHeight / targetHeight
                    : options.outWidth / targetWidth;
            sampleSize = (int) Math.pow(2d,
                    Math.floor(Math.log(sampleSize) / Math.log(2d)));
        }
        options.inJustDecodeBounds = false;
        options.inTempStorage = new byte[128];
        while (true) {
            try {
                options.inSampleSize = (int) sampleSize;
                           // here you can do you Decode process
                //mBitmap = BitmapFactory.decodeFile(intent_data2, options);

                break;
            } catch (Exception ex) {
                try {
                    sampleSize = sampleSize * 2;
                } catch (Exception ex1) {

                }
            }
        }
        return scaledBitmap;

    }
Aerrow
  • 12,086
  • 10
  • 56
  • 90