我尝试将 jpeg 资源图像加载到 ARGB_8888 格式的位图:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap b = BitmapFactory.decodeResource(resources, resId, opts);
Log.d("test", b.getConfig().toString());
这里的resId是一个jpeg图片资源的id。 输出为“RGB_565”。 在 android 2.2 和 2.3 的模拟器中试过这个。
“inPreferredConfig”的文档说:
If this is non-null, the decoder will try to decode into this internal configuration. If it is null, or the request cannot be met, the decoder will try to pick the best matching config based on the system's screen depth, and characteristics of the original image such as if it has per-pixel alpha (requiring a config that also does). Image are loaded with the ARGB_8888 config by default.
那么我是否遇到了“无法满足请求”的情况? :) 但老实说,我看不出将 RGB_565 解码为 ARGB_8888 有多么困难。
所以我想也许我做错了或者这是 Android 中的错误...
最佳答案
加载 jpeg 时,您必须将 alpha channel 设置为 true:
bitmap.setHasAlpha(true);
关于android - BitmapFactory.decodeResource() 忽略 jpg 图像的 inPreferredConfig 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10413628/