4

I have an app with two views - one on top of another. On the top one I use a Bitmap (ARGB_8888) loaded from a PNG resource and I play with its alpha channel to make some parts of it disappear so the one below becomes visible. All works fine if the source image has at least a single transparent pixel to start with. But if the source PNG has no transparent pixels then changing it alpha to 0 makes the pixel I changed black, not transparent.

Any ideas what could be done to fix it? anything like:

aaptOptions {
    cruncherEnabled = false
}

but another option?

Currently I modify the source images before compiling by making a tiny area of it "semi-transparent" but would like to avoid that.

Adrian Petrescu
  • 16,629
  • 6
  • 56
  • 82
Piotr
  • 1,597
  • 3
  • 18
  • 25
  • have you seen this question http://stackoverflow.com/questions/2881939/android-read-png-image-without-alpha-and-decode-as-argb-8888 ? – Rafal Malek Sep 16 '16 at 14:59
  • Almost sounds like your images were 24bit if they didn't have transparency (32Bit). So you are correct in the answer of needing to convert it to have alpha either while loading it like you do or saving the file itself as 32bit. – Roger Garstang Sep 21 '16 at 20:11

1 Answers1

3

Ok. Finally got it.

I had to add one line. Instead of:

mBitmap = BitmapFactory.decodeResource(getResources(), getResourceID()).copy(Bitmap.Config.ARGB_8888, true);

I am now using:

mBitmap = BitmapFactory.decodeResource(getResources(), getResourceID()).copy(Bitmap.Config.ARGB_8888, true);
mBitmap.setHasAlpha(true);

and there is no need to add a transparent pixel on the source image!

Piotr
  • 1,597
  • 3
  • 18
  • 25