Android Mask bitmap on canvas gen a black space

前端 未结 4 1791
滥情空心
滥情空心 2020-11-28 23:16

I have a mask bitmap with a half is red color and ones is transparent like this https://www.dropbox.com/s/931ixef6myzusi0/s_2.png

I want to use mask bitmap to draw c

4条回答
  •  臣服心动
    2020-11-28 23:39

    I encountered the same problem in my custom view and instead of decoding the bitmap from a resource, I had created the original bitmap and the masking bitmap from the scratch via canvas.draw*() methods (since both the original and mask are basic shapes). I was getting the blank opaque space instead of a transparent one. I fixed it by setting a hardware layer to my view.

    View.setLayerType(LAYER_TYPE_HARDWARE, paint);
    

    More info on why this is to be done here: https://stackoverflow.com/a/33483016/4747587

提交回复
热议问题