Skip to content

Commit

Permalink
Merge pull request #3 from skellock/fix-android-cache-invalidation
Browse files Browse the repository at this point in the history
Invalidates the Android view cache after each shot.
  • Loading branch information
gre authored Aug 25, 2016
2 parents 04b319a + 2a42744 commit ee38431
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 ee38431

Please sign in to comment.