I have a ARGB_8888 Bitmap, which I need to apply an alpha mask to prior to painting to the canvas. The Alpha mask is a stream of bytes representing the alpha channel for the image. I could retrieve the int array of pixel values for the Bitmap, loop through the array and set the alpha for each pixel, create a bitmap from the new pixel values, and paint it to the canvas; but this seems extremely inefficient. So, I was hoping to use some built in functionality for apply masks to bitmaps; but can’t find anything useful. Any advice?
Share
First things first, make sure you have a mutable Bitmap with
Bitmap.isMutable().Have you tried
Bitmap.setHasAlphaand using arithmetic operations on your mutableBitmapto simply “add” the alpha channel?That is, if you have a pixel that is
#00FF0000, you can add#FF000000to make it completely transparent.This would be much more efficient than copying to a new
Bitmap.Maybe something like
Hope this helps!