2017-11-25 65 views
0

我想从32位PNG图像创建一个带有ALPHA_8配置的位图。要做到这一点,我请拨打decodeResource(Resources res, int id, Options opts),其中opts.inPreferredConfig = Bitmap.Config.ALPHA_8。但是,它会返回带有ARGB_8888配置的位图:为什么BitmapFactory.decodeResource与inPreferredConfig = Bitmap.Config.ALPHA_8会返回带有Bitmap.Config.ARGB_8888的位图?

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inPreferredConfig = Bitmap.Config.ALPHA_8; 

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), id, options); 

// Output: "bitmap.getConfig() returns ARGB_8888" 
Log.w(tag, "bitmap.getConfig() returns " + bitmap.getConfig()); 

为什么会发生?如何使其正常工作?

回答

0

因为你的源位图不能被ALPHA_8解码,所以Android自动挑选ARGB888解码。

相关问题