Skip to content

Commit

Permalink
Invalidates the Android view cache after each shot.
Browse files Browse the repository at this point in the history
  • Loading branch information
skellock committed Aug 25, 2016
1 parent 04b319a commit 2a42744
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@ private void captureView (View view, OutputStream os) {
if (w <= 0 || h <= 0) {
throw new RuntimeException("Impossible to snapshot the view: view is invalid");
}
if (!view.isDrawingCacheEnabled())
view.setDrawingCacheEnabled(true);

Bitmap bitmap = view.getDrawingCache();
if (bitmap == null)
view.setDrawingCacheEnabled(true);
bitmap = view.getDrawingCache();

if (width != null && height != null && (width != w || height != h)) {
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
}
if (bitmap == null) {
throw new RuntimeException("Impossible to snapshot the view");
}
bitmap.compress(format, (int)(100.0 * quality), os);
view.setDrawingCacheEnabled(false);
}
}

0 comments on commit 2a42744

Please sign in to comment.