在我的应用程序中,我使用SQLite数据库来存储大量图像的数据。某些图像可以达到600x600像素。我使用自定义列表来创建位图。我知道有一个方法bitmap.recycle();但我不知道如何在listview中使用它。OutOfMemoryError android bitmap listview
0
A
回答
0
这里是处理位图在Android中
首先,你要计算出位的sampleBitmapSize的解决方案(加载相同的位图的较低版本)
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);
}
下面是UTIL功能计算InSampleSize(一个定义位图质量值(评分)的整数)。
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;
}
+0
使用这种技术,我可以在非UI线程上轻松处理25kx25k像素的图像。 –
+0
谢谢,并且在reqWidth和reqHeight参数中,我应该放置所需的大小,例如600x600? –
+0
是的,它是你想要的位图的高度和宽度(原始位图的较小版本)。 –
相关问题
- 1. outofmemoryerror while making bitmap
- 2. Listview with bitmaps,outofmemoryerror
- 3. Android:“java-lang-outofmemoryerror-bitmap-size-exceed-vm-budget-android”从sdcard加载位图?
- 4. ListView中的位图OutOfMemoryError
- 5. Bitmap OutOfMemoryError即使使用回收()
- 6. 的OutOfMemoryError ListView中
- 7. Android - BitmapFactory.decodeByteArray - OutOfMemoryError(OOM)
- 8. Android上的Xamarin.Forms ListView OutOfMemoryError异常
- 9. Android Viewpager OutOfMemoryError Fragment
- 10. Android ViewAnimator和OutOfMemoryError
- 11. setpixel in bitmap android
- 12. android bitmap dithering
- 13. OutOfMemoryError Android
- 14. Android OutOfMemoryError
- 15. Android OutOfMemoryError
- 16. OutOfMemoryError Android
- 17. Android OutofMemoryerror?
- 18. 使用无限滚动时获取outofmemoryerror android listview
- 19. 的OutOfMemoryError位图的Android
- 20. 在Android中的延迟加载OutOfMemoryError android
- 21. 适用于Android的Mono - OutOfMemoryError
- 22. Android ListView OutOfMemoryError:位图大小超过虚拟机预算
- 23. Android Bitmap降尺寸
- 24. Android上的Bitmap LockBits?
- 25. Android bitmap paint size widget
- 26. Android itext pdf库OutOfMemoryError
- 27. Android ImageSwitcher OutOfMemoryError
- 28. Android获取OutOfMemoryError
- 29. OutOfMemoryError崩溃Android
- 30. 抛出OutOfMemoryError Android
的可能重复的[奇异出存储器问题在加载图像以Bitmap对象(http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading -an-image-to-a-bitmap-object) – tyczj