How can I do this? There's a setAlpha but no getAlpha.
Actually, you need to use getOpacity()
because get alpha existe only for ColorDrawable
, Transformation
and a few others. and you need to use it on the drawable of the ImageView
not the view itself.
There is no easy way to do this. This is because an ImageView
might have been set with a Bitmap
, a StateListDrawable
, a ColorDrawable
, or something else entirely. Only one of those classes has a single color; on any other drawable the alpha might be different for each pixel (pixels are in ARGB format, w/ 1 byte each for alpha, red, green, and blue). I'm pretty sure the setAlpha()
method only works on drawables that support it, as mentioned by Sephy above.
What exactly do you need to know about the image's transparency? If you know what the ImageView will be filled with ahead of time, then perhaps you can extract the alpha beforehand. If you don't have direct access to the alpha, but you are able to determine the color, then the alpha will be equal to color >>> 24
.