Punch a hole in a rectangle overlay with HW acceleration enabled on View

前端 未结 1 2026
说谎
说谎 2020-12-12 17:35

I have a view which does some basic drawing. After this I want to draw a rectangle with a hole punched in so that only a region of the previous drawing is visible. And I\'d

相关标签:
1条回答
  • 2020-12-12 18:05

    Instead of allocating a new canvas on each repaint, you should be able to allocate it once and then reuse the canvas on each repaint.

    on init and on resize:

    Bitmap b = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    

    on repaint:

    b.eraseColor(Color.TRANSPARENT);
        // needed if backColor is not opaque; thanks @JosephEarl
    c.drawColor(backColor);
    c.drawCircle(cx, cy, radius, eraser);
    
    canvas.drawBitmap(b, 0, 0, null);
    
    0 讨论(0)
提交回复
热议问题