从Android中的WebView截图

从Android中的WebView截图,android,webview,Android,Webview,我有html源代码,并使用Web视图加载此源代码: WebView webView = (WebView) new WebView(getActivity()); webView = (WebView) rootView.findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled(true); String sourceHtml = (String) this.

我有html源代码,并使用Web视图加载此源代码:

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");

现在我想在SD卡中以位图或其他形式保存此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) {}

我有这个错误:01-04 14:31:38.930:E/AndroidRuntime(32609):java.lang.NullPointerException 01-04 14:31:38.930:E/AndroidRuntime(32609):在felastech.websourcerequest.WebChange.onCreateView(WebChange.java:65)01-04 14:31:38.930:E/AndroidRuntime(32609):在android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)01-04 14:31:38.930:E/AndroidRuntime(32609):在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)中,此状态为:Picture Picture=webView.capturePicture();返回null..为什么?尝试在onPageFinished中使用它现在我有以下内容:01-04 15:42:24.760:E/AndroidRuntime(7139):致命异常:main 01-04 15:42:24.760:E/AndroidRuntime(7139):java.lang.IllegalArgumentException:宽度和高度必须大于0 01-04 15:42:24.760:E/AndroidRuntime(7139):在安卓.graphics.Bitmap.createBitmap(Bitmap.java:638)01-04 15:42:24.760:E/AndroidRuntime(7139):在android.graphics.Bitmap.createBitmap(Bitmap.java:620)01-04 15:42:24.760:E/AndroidRuntime(7139):在felastech.WebChange$1.onPageFinished(WebChange.java:69)