我尝试将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通道设置为true:
bitmap.setHasAlpha(true);