从我的应用程序中,我试图从其他已安装的应用程序中获取特定的可绘制资源。资源始终存在。我用:
Resources resources = activity.getPackageManager().getResourcesForApplication(packageName);
int previewResID = resources.getIdentifier("image", "drawable", packageName);
Drawable myThemePreview = resources.getDrawable(previewResID);
在drawable转换为位图并显示给用户
之前,我在最后一行得到了内存不足答案 0 :(得分:0)
您可以使用BitmapFactory::decodeResource使用带有指定inSampleSize的BitmapFactory.Options来减少内存。
它看起来像这样:
Resources resources = activity.getPackageManager().getResourcesForApplication(packageName);
int previewResID = resources.getIdentifier("image", "drawable", packageName);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeResource(resources,previewResId,options);