我有一个单通道的PNG文件,想将其用作Porter-Duff绘图操作的Alpha蒙版。如果我不使用任何选项加载它,则生成的Bitmap具有RGB_565配置,即被视为灰度图像。如果我将首选配置设置为ALPHA_8,则它将以灰度ARGB_8888的形式加载。
我该如何说服Android将此文件视为Alpha蒙版而不是灰度图像?
mask1 = BitmapFactory.decodeStream(pngStream);
// mask1.getConfig() is now RGB_565
BitmapFactory.Options maskOpts = new BitmapFactory.Options();
maskOpts.inPreferredConfig = Bitmap.Config.ALPHA_8;
mask2 = BitmapFactory.decodeStream(pngStream, null, maskOpts);
// mask2.getConfig() is now ARGB_8888 (the alpha channel is fully opaque)