Je reçois l'erreur: java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=12295KB, Allocated=3007KB, Bitmap Size=15621KB)
Android Bitmap plus grand que HEAPSIZE
La taille du bitmap est plus grand que mon HEAPSIZE .. Alors, comment puis-je faire le bitmap plus petit? Voici le code où il se bloque:
private Bitmap getPicture(int position) {
Bitmap bmpOriginal = BitmapFactory.decodeFile(mFileLocations.get(position));
Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.RGB_565);
Canvas tempCanvas = new Canvas(bmResult);
tempCanvas.rotate(90, bmpOriginal.getWidth()/2, bmpOriginal.getHeight()/2);
tempCanvas.drawBitmap(bmpOriginal, 0, 0, null);
bmpOriginal.recycle();
}
il se bloque à la ligne:
Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.RGB_565);
et mon decodeFile:
private Bitmap decodeFile(String f){
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//The new size we want to scale to
final int REQUIRED_SIZE=70;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(o.outWidth/scale/2>=REQUIRED_SIZE && o.outHeight/scale/2>=REQUIRED_SIZE)
scale*=2;
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {
Log.d(LOG_TAG, "Failed to decode file");
}
return null;
}
Je ne vois pas où vous utilisez votre méthode 'decodeFile'. Vous utilisez simplement 'BitmapFactory.decodeFile'. – kabuko
Oh wow, je l'utilisais ailleurs mais je suppose que j'ai dû le changer quand j'essayais des choses. Merci – user1154920