1

I want to download photos from your disk. I used to have a bug OutOfMemory. I coped with this error, but now on some phones I get the error "Bitmap too large to be uploaded into a texture (1840x3264, max = 2048x2048)". In this case, when the picture is uploaded my app begins to slow, jerky, slow down. Please tell me how to upload pictures from the disk so as to avoid these mistakes and express

AndyN
  • 1,678
  • 1
  • 15
  • 30
user3815165
  • 248
  • 2
  • 15

2 Answers2

1

use this method to create your bitmap-

 Bitmap bm=decodeSampledBitmapFromPath(src, reqWidth, reqHeight);
 // might be your Screen Height and Width in your Case

use this Defination-

public Bitmap decodeSampledBitmapFromPath(String path, int reqWidth,
    int reqHeight) {

final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);

options.inSampleSize = calculateInSampleSize(options, reqWidth,
        reqHeight);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap bmp = BitmapFactory.decodeFile(path, options);
return bmp;
}
}
  public int calculateInSampleSize(BitmapFactory.Options options,
    int reqWidth, int reqHeight) {

final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {
    if (width > height) {
        inSampleSize = Math.round((float) height / (float) reqHeight);
    } else {
        inSampleSize = Math.round((float) width / (float) reqWidth);
     }
 }
 return inSampleSize;
}

Note- Make Your reqWidth and reqHeight according to your sceenSize.

Tarun Varshney
  • 16,808
  • 6
  • 32
  • 47
0

You can't increase the heap size dynamically.

you can request to use more by using

 android:largeHeap="true"

in the manifest.

also, you can use native memory (NDK & JNI) , so you actually bypass the heap size limitation.

here are some posts made about it:

and here's a library made for it:

happy coding

regards maven

Community
  • 1
  • 1
Maveňツ
  • 8,899
  • 14
  • 49
  • 85
  • @TarunVarshney better you check this http://stackoverflow.com/questions/11275650/how-to-increase-heap-size-of-an-android-application – Maveňツ Sep 17 '14 at 05:45
  • By android:largeHeap="true" app will increase the heap size. and where that heap size will come from? obviously from other app running on that heap. so it might kill other apps. and make your app slower. dear.. – Tarun Varshney Sep 17 '14 at 05:54