@ SuppressWarnings ( "deprecation" ) private void drawRoundedHole ( Canvas canvas ) { paint . setStyle ( Paint . Style . FILL ) ; paint . setColor ( backColor ) ; // Punching hole in background color requires offscreen drawing if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . LOLLIPOP ) { canvas . saveLayer ( 0 , 0 , canvas . getWidth ( ) , canvas . getHeight ( ) , null ) ; } else { canvas . saveLayer ( 0 , 0 , canvas . getWidth ( ) , canvas . getHeight ( ) , null , 0 ) ; } canvas . drawPaint ( paint ) ; final float rx = rounding * 0.5f * areaRect . width ( ) ; final float ry = rounding * 0.5f * areaRect . height ( ) ; canvas . drawRoundRect ( areaRect , rx , ry , paintClear ) ; canvas . restore ( ) ; }
If cropping area is rounded we have to use off - screen buffer to punch a hole