androidimageviewalphacolorfilter

How can I make an ImageView that doesn't draw the transparent parts of the image?


I need my custom ImageView (called ItemAnimationView) to not draw any part of its image that is transparent.

I use this class for a lot of instances and for a lot of different images, so it would be best if I could solve this problem only with methods that I can call on ImageView, as editing all the different images manually won't work.

So is there some kind of ColorFilter that does not only filter out one certain color but instead every pixel that is transparent to any degree?

Also it would be quite convenient if there was a way to do this without accessing the actual bitmap, as the only lines of code I use for the view so far are

setImageResource(item.getResourceID());

and some animating, so I don't have the associated Bitmap object.


Solution

  • I achieved the desired effect using a ColorMatrixColorFilter with this matrix:

    {1f,0f,0f,0f,0f,
    0f,1f,0f,0f,0f,
    0f,0f,1f,0f,0f,
    0f,0f,0f,256f,-256*254};