Skip to content

Commit

Permalink
Merge pull request #122 from PauloMelo/#121
Browse files Browse the repository at this point in the history
Android takeScreenshot does not work properly.
  • Loading branch information
pichillilorenzo authored Oct 24, 2019
2 parents f1cb348 + 39788a0 commit 996ec1e
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 996ec1e

Please sign in to comment.