从Android中的WebView截取屏幕截图

时间:2014-01-04 09:54:28

标签: android webview

我有html源代码,使用WebView i加载此源代码:

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,我按照一些指南但从不工作,我怎么做?

1 个答案:

答案 0 :(得分:2)

尝试使用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) {}