Android How to - Get Bitmap from visiable region of a WebView








Question

We would like to know how to get Bitmap from visiable region of a WebView.

Answer

//from   w w w  .  j av  a 2 s  .  com
import android.graphics.Bitmap;
import android.webkit.WebView;

public class Main {
  public static Bitmap getBitmapForVisibleRegion(WebView webview) {
      Bitmap returnedBitmap = null;
      webview.setDrawingCacheEnabled(true);
      returnedBitmap = Bitmap.createBitmap(webview.getDrawingCache());
      webview.setDrawingCacheEnabled(false);
      return returnedBitmap;
  }
  
}