I have a grayscale JPG picture, and I'd like to load it into Bitmap of format Bitmap.Config.ALPHA_8
. Is that possible, how can I do that?
It's straightforward to load alpha channel from a PNG (which can have empty R,G,B channels), but I'd like to use JPG for compression.
This is a followup question to How to combine two opaque bitmaps into one with alpha channel?
Best Answer
ColorMatrix to rescue!
Quoting Android docs, ColorMatrix:
Set up color matrix that takes alpha value from red channel (or green, or blue, doesn't matter for grayscale...), then use it in
Paint.setColorFilter()
. Here's a more or less complete example: