简体   繁体   中英

android webview full page screen capture

I am trying to capture webview full page content as a screenshot(bitmap) in android but no luck. Tested many solutions suggested in stackoverflow and other sites. Please help.

Bitmap bitmap = Bitmap.createBitmap(webView.getWidth(), webView.getContentHeight(), Bitmap.Config.ARGB_4444);
webView.draw(new Canvas(bitmap));

You can try this :

    WebView w ;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    w = new WebView(this);
    w.setWebViewClient(new WebViewClient()
    {
            public void onPageFinished(WebView view, String url)
            {
                    Picture picture = view.capturePicture();
                    Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
                    picture.getHeight(), Bitmap.Config.ARGB_8888);
                    Canvas c = new Canvas( b );

                    picture.draw( c );
                    FileOutputStream fos = null;
                    try {

                        fos = new FileOutputStream( "mnt/sdcard/yahoo.jpg" );
                            if ( fos != null )
                            {
                                b.compress(Bitmap.CompressFormat.JPEG, 100, fos);

                                fos.close();
                            }
                        }
                   catch( Exception e )
                   {

                   }
          }
      });

    setContentView(w);
    w.loadUrl("http://search.yahoo.com/search?p=android");
}

I found this from hear.. click. did you try in this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM