Android 快照webview返回空白图像

Android 快照webview返回空白图像,android,webview,snapshot-view,Android,Webview,Snapshot View,我想快照WebView的全部内容。但是,返回的图像始终为空。你能看一下并告诉我哪里错了吗 请不要建议我使用capturePicture函数,因为该函数目前已被弃用。 一些代码 public class WebViewActivity extends Activity { private static WebView webView; public void onCreate(Bundle savedInstanceState) {

我想快照WebView的全部内容。但是,返回的图像始终为空。你能看一下并告诉我哪里错了吗

请不要建议我使用capturePicture函数,因为该函数目前已被弃用。

一些代码

   public class WebViewActivity extends Activity {

        private static WebView webView;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);

            webView = (WebView) findViewById(R.id.webView1);
    webView.loadUrl("http://developer.android.com/training/basics/firstapp/creating-project.html");

    webView.setWebViewClient(new WebViewClient() {

        public void onPageFinished(WebView view, String url) {
            // do your stuff here
            webView.measure(MeasureSpec.makeMeasureSpec(
                    MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            webView.layout(0, 0, webView.getMeasuredWidth(),
                    webView.getMeasuredHeight());
            webView.setDrawingCacheEnabled(true);
            webView.buildDrawingCache();
            Bitmap bm = Bitmap.createBitmap(webView.getMeasuredWidth(),
                    webView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

            Canvas bigcanvas = new Canvas(bm);
            Paint paint = new Paint();
            int iHeight = bm.getHeight();
            bigcanvas.drawBitmap(bm, 0, iHeight, paint);
            if (bm != null) {
                try {
                    String path = Environment.getExternalStorageDirectory()
                            .toString();
                    OutputStream fOut = null;
                    File file = new File(path, "/aaaa.png");
                    fOut = new FileOutputStream(file);

                    bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
                    fOut.flush();
                    fOut.close();
                    bm.recycle();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });
}
layout.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
/>


非常感谢

我找到了解决办法。看看这个

我使用onDraw来替换capturePicture函数,该函数在API 19中被弃用。如果你有更好的解决方案,请告诉我,我很感激。谢谢