简体   繁体   中英

How can I load PNG-Files as ARGB_8888 even if they have no alpha channel?

I have the following code to load png files:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = false;
map =  BitmapFactory.decodeResource(getResources(), mapid, options);

Unfortunately it loads images as RGB_565 if they have no alpha channel. How can I prevent this and consistently load them every time unchanged (no dithering, no conversion, or anything else) ?

If this is not possible then is there maybe another way to load PNG files as ARGB_8888 without BitmapFactory ?

Or is there maybe another format that can be used instead of PNG that also supports an Alpha channel and always delivers ARGB_8888 bitmaps ?

PS: I am using Android 2.3.4.

I got an idea.

  1. Try to load the PNG bitmap without a PreferredConfig.
  2. Get the image pixels.
  3. Create a new bitmap with the preferred config you want (ARGB_8888).
  4. Set the pixels of the PNG bitmap in the new bitmap.

I think it should run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM