From 39788a016346e1f57a33ec8fe414ed3dbbe10615 Mon Sep 17 00:00:00 2001 From: Paulo Melo Date: Mon, 24 Jun 2019 10:33:14 +0100 Subject: [PATCH] Android takeScreenshot does not work properly. --- .../InAppWebView/InAppWebView.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java index 1d81944ab..d5b9129d4 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java @@ -298,19 +298,27 @@ public void clearAllCache() { } public byte[] takeScreenshot() { - Picture picture = capturePicture(); + float scale = getScale(); + int height = (int) (getContentHeight() * scale + 0.5); + Bitmap b = Bitmap.createBitmap( getWidth(), - getHeight(), Bitmap.Config.ARGB_8888); + height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); - picture.draw(c); + draw(c); + int scrollOffset = (getScrollY() + getMeasuredHeight() > b.getHeight()) + ? b.getHeight() : getScrollY(); + Bitmap resized = Bitmap.createBitmap( + b, 0, scrollOffset, b.getWidth(), getMeasuredHeight()); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - b.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); + resized.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); try { byteArrayOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } + resized.recycle(); return byteArrayOutputStream.toByteArray(); }