Android BitmapFactory.decodeResource 和 drawable* 文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11756231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
BitmapFactory.decodeResource and drawable* folders
提问by Thomas Calc
I am wondering if decodeResource (Resources res, int id, BitmapFactory.Options opts)
takes into account the drawable-ldpi,mdpi,hdpi etc. folders.
我想知道是否decodeResource (Resources res, int id, BitmapFactory.Options opts)
考虑了 drawable-ldpi、mdpi、hdpi 等文件夹。
I checked the source code, and it doesn't look like that, but I may be missing something.
我检查了源代码,它看起来不像,但我可能遗漏了一些东西。
(Generally, where are the R.drawable. resolved in Android source? I was unable to find it.)
(一般来说,Android 源中的 R.drawable. 在哪里解析?我找不到它。)
回答by flawyte
Yes it takes it into account. For example if you do :
是的,它考虑到了它。例如,如果你这样做:
Resources res = getContext().getResources();
int id = R.drawable.image;
Bitmap b = BitmapFactory.decodeResource(res, id);
The bitmap will be different if "image" is present in all of the drawables folders.
So I think using the overloaded method decodeResource (Resources res, int id, BitmapFactory.Options opts)
will work in the same way.
如果所有 drawables 文件夹中都存在“图像”,则位图将有所不同。所以我认为使用重载方法decodeResource (Resources res, int id, BitmapFactory.Options opts)
会以同样的方式工作。