How to make Canvas draw area transparent in android?

前端 未结 9 2092
悲&欢浪女
悲&欢浪女 2020-12-08 09:01

I would like to make Canvas area transparent because I would like to add an Image behind it so that Canvas actions happen above the image.My code for the canvas is here

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 09:25

    You can create a Bitmap of the same size as the canvas. Erase all the colors of the bitmap using Color.TRANSPARENCY and set it as a canvas bitmap:

    Bitmap transparentBitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(),
    Bitmap.Config.ARGB_8888);
    transparentBitmap.eraseColor(Color.TRANSPARENT);
    canvas.setBitmap(transparentBitmap);
    

提交回复
热议问题