code: public static Bitmap viewToImage(Context context, WebView viewToBeConverted) {
          int extraSpace = 2000; //because getContentHeight doesn't always return the full screen height.
          int height = viewToBeConverted.getContentHeight() + extraSpace;
  
          Bitmap viewBitmap = Bitmap.createBitmap(viewToBeConverted.getWidth(), height, Bitmap.Config.ARGB_8888);
          Canvas canvas = new Canvas(viewBitmap);
          viewToBeConverted.draw(canvas);
  
          //If the view is scrolled, cut off the top part that is off the screen.
          try {
              int scrollY = viewToBeConverted.getScrollY();
              if (scrollY > 0) {
                  viewBitmap = Bitmap.createBitmap(viewBitmap, 0, scrollY, viewToBeConverted.getWidth(), height - scrollY);
              }
          } catch (Exception ex) {
              Log.e("Caffeine", "Could not remove top part of the webview image.  ex=" + ex);
          }
  
          return viewBitmap;
      }
docs: Convert view to an image.  Can be used to make animations smoother.
  
  @param context           The current Context or Activity that this method is called from.
  @param viewToBeConverted View to convert to a Bitmap.
  @return Bitmap object that can be put in an ImageView.  Will look like the converted viewToBeConverted.