加载应用程序的图标和获取内存不足的异常而调整 [英] Load applications icons and getting OutOfMemory exception while resizing
问题描述
下面是code:(所有异步同时显示进度条执行)
Here is the code : (All executed async while showing a progress bar)
List<ResolveInfo> apps = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
for (ResolveInfo app : apps) {
String label = app.activityInfo.loadLabel(pm).toString();
Drawable icon = app.activityInfo.loadIcon(pm);
Drawable resizedIcon = null;
if (icon instanceof BitmapDrawable) {
resizedIcon = Graphics.resize(icon, res, iconW, iconH);
}
AppInfo ai = new AppInfo(app, label, resizedIcon);
items.add(ai);
}
下面是 Graphics.resize()
:
Bitmap b = ((BitmapDrawable)image).getBitmap();
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, widthPx, heightPx, false);
b.recycle();
return new BitmapDrawable(res, bitmapResized);
通常这一切工作正常,但我没有得到有关内存溢出异常,同时呼吁 Bitmap.createScaledBitmap
(我试图重新大小到32dp)的报告结果
我读了有关处理及显示位图,但在这里,我想在用户看到的应用程序名称要立即显示的应用程序图标,而不是刚开始加载。 (我可以通过实现 RecyclerView
)
Generally it all works fine, but I did get a report about out of memory exception while calling Bitmap.createScaledBitmap
(i'm trying to re-size to 32dp)
I read about handling and displaying bitmaps , but here, I want the app icon to be displayed immediately while the user sees the app name, and not just start being loaded. (which I can achieve by using RecyclerView
)
推荐答案
您可以设置大型堆属性为true。
You can set the large heap attribute to true.
还有一种方式,可以使用图像加载器的形象,所以你得到的图标将被存储在设备上。
There is also a way you can use image loader in that image so the icon you get will be stored on the device.
这篇关于加载应用程序的图标和获取内存不足的异常而调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!