捕获android webview图像并保存到png/jpeg

use*_*524 3 html android cordova

我正在尝试在android/phonegap应用程序上实现css3页面翻转效果.为此,我需要将当前webview动态保存到png或jpeg,以便可以将其加载到页面翻转html中的div.我注意到android的文档中的Picture类,但我不确定是否可以转换和保存.这可以通过JS完成吗?有任何想法吗?

谢谢

Mad*_*uri 6

尝试使用以下代码捕获webview并将jpg保存到sdcard.

webview.setWebViewClient(new WebViewClient() {

    @Override
    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( "/sdcard/"  + "page.jpg" );
            if ( fos != null ) {
                b.compress(Bitmap.CompressFormat.JPEG, 90, fos );
                fos.close();
            }
        } 
        catch( Exception e ) {
            System.out.println("-----error--"+e);
        }
    }
});

webview.loadUrl("http://stackoverflow.com/questions/15351298/capturing-android-webview-image-and-saving-to-png-jpeg");
Run Code Online (Sandbox Code Playgroud)