Dans mon application, j'utilise une base de données SQLite pour stocker les données d'un grand nombre d'images. Certaines images peuvent atteindre 600 x 600 pixels. J'utilise une liste personnalisée pour créer les bitmaps. Je sais qu'il existe une méthode bitmap.recycle(); mais je ne suis pas sûr de savoir comment l'utiliser avec un listview.OutOfMemoryError android Bitmap listview
Répondre
Voici la solution pour gérer bitmaps dans Android
D'abord, vous devez calculer le sampleBitmapSize du bitmap (pour charger la version inférieure du même bitmap)
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
est inférieure à la fonction util pour calculer InSampleSize (un entier qui définit la valeur (rating) de la qualité d'un bitmap).
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height/2;
final int halfWidth = width/2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight/inSampleSize) > reqHeight
&& (halfWidth/inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
Log.i("ImageUtil", "InSampleSize: "+inSampleSize);
return inSampleSize;
}
en utilisant cette technique je peux manipuler l'image de pixel 25kx25k facilement sur un fil non-ui. –
Merci, et dans les paramètres reqWidth et reqHeight je devrais mettre les tailles nécessaires telles que 600x600? –
Oui, c'est la hauteur et la largeur de l'image que vous voulez avoir (la plus petite version de l'image originale). –
- 1. Android - AsyncTask travailler avec Bitmap - OutOfMemoryError
- 2. Redimensionner un bitmap dans android - Exception OutOfMemoryError
- 3. Android ListView Bitmap Optimization
- 4. OutOfMemoryError chargement Bitmap via DefaultHttpClient
- 5. OutOfMemoryError lors du redimensionnement Bitmap
- 6. Mono pour Android - OutOfMemoryError
- 7. Android Bitmap Compression insuffisante et provoquant des pannes OutOfMemoryError
- 8. Android OutOfMemoryError: taille de bitmap dépasse le budget VM
- 9. Android La taille du bitmap OutOfMemoryError dépasse le budget VM
- 10. OutOfMemoryError Android
- 11. Android OutOfMemoryError
- 12. Android OutOfMemoryError avec XML
- 13. android chaîne concat OutOfMemoryError
- 14. Lancer OutOfMemoryError Android
- 15. OutOfMemoryError: la taille du bitmap dépasse le budget VM
- 16. OutOfMemoryError lors de la création d'une image bitmap
- 17. Comment gérer OutOfMemoryError dans Android?
- 18. Android OutOfMemoryError Crash dans startManagingCursor
- 19. Android octets à bitmap
- 20. Android: OutofMemoryError: la taille de bitmap dépasse le budget VM sans raison je peux voir
- 21. Rotation d'une image dans Android sans OutOfMemoryError ou downscaling
- 22. android OutOfMemoryError sur WVGA800 et pas petit format écran
- 23. Android set Image Bitmap question
- 24. oups! OutOfMemoryError
- 25. comment éviter OutOfMemoryError
- 26. Android OutOfMemoryError dans la ligne SetContentView
- 27. OutOfMemoryError
- 28. Picasso produisant OutOfMemoryError
- 29. Comment utiliser bitmap recycler dans android?
- 30. Android listview image lag
double possible de [étrange de problème de mémoire lors du chargement d'une image à un objet Bitmap] (http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading -an-image-to-a-bitmap-object) – tyczj