diff --git a/android/src/main/java/com/horcrux/svg/GroupView.java b/android/src/main/java/com/horcrux/svg/GroupView.java index db20fd2ec..9075b7c17 100644 --- a/android/src/main/java/com/horcrux/svg/GroupView.java +++ b/android/src/main/java/com/horcrux/svg/GroupView.java @@ -97,19 +97,24 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) { final SvgView svg = getSvgView(); final GroupView self = this; final RectF groupRect = new RectF(); - if (mLayerBitmap == null) { - mLayerBitmap = - Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); - mLayerCanvas = new Canvas(mLayerBitmap); + + if (mOpacity != 1) { + if (mLayerBitmap == null) { + mLayerBitmap = + Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); + mLayerCanvas = new Canvas(mLayerBitmap); + } else { + mLayerBitmap.recycle(); + mLayerBitmap = + Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); + mLayerCanvas.setBitmap(mLayerBitmap); + } + // Copy current matrix from original canvas + mLayerCanvas.save(); + mLayerCanvas.setMatrix(canvas.getMatrix()); } else { - mLayerBitmap.recycle(); - mLayerBitmap = - Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); - mLayerCanvas.setBitmap(mLayerBitmap); + mLayerCanvas = canvas; } - // Copy current matrix from original canvas - int saveCount = mLayerCanvas.save(); - mLayerCanvas.setMatrix(canvas.getMatrix()); elements = new ArrayList<>(); for (int i = 0; i < getChildCount(); i++) { @@ -157,13 +162,15 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) { } } - // Restore copied canvas and temporary reset original canvas matrix to draw bitmap 1:1 - mLayerCanvas.restoreToCount(saveCount); - saveCount = canvas.save(); - canvas.setMatrix(null); - mLayerPaint.setAlpha((int) (mOpacity * 255)); - canvas.drawBitmap(mLayerBitmap, 0, 0, mLayerPaint); - canvas.restoreToCount(saveCount); + if (mOpacity != 1) { + // Restore copied canvas and temporary reset original canvas matrix to draw bitmap 1:1 + mLayerCanvas.restore(); + int saveCount = canvas.save(); + canvas.setMatrix(null); + mLayerPaint.setAlpha((int) (mOpacity * 255)); + canvas.drawBitmap(mLayerBitmap, 0, 0, mLayerPaint); + canvas.restoreToCount(saveCount); + } this.setClientRect(groupRect); popGlyphContext(); }