从Android中的WebView截取屏幕截图

我有html源代码和WebView我加载此源代码:

WebView webView = (WebView) new WebView(getActivity()); 
        webView = (WebView) rootView.findViewById(R.id.webView1);

        webView.getSettings().setJavaScriptEnabled(true);
        String sourceHtml = (String) this.getActivity().getIntent().getExtras().get(ROW_ID1);


        webView.loadData(sourceHtml, "text/html", "UTF-8");

现在我想在BitMap或其他SdCard中保存这个WebView,我按照一些指南但从不工作,我怎么能这样做?

最佳答案 尝试使用capturePicture函数:

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/screenshot.jpg" );
        if ( fos != null )
        {
            b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.close();
        }
    }
catch(Exception e) {}
点赞