捕获的Andr​​oid的WebView图像和保存为PNG / JPEG保存为、图像、oid、Andr

2023-09-13 00:36:57 作者:悲傷式、童年

我想实现CSS3翻页效果在安卓/ PhoneGap的应用程序。要做到这一点,我需要当前的web视图动态地保存到PNG或JPEG,以便它可以加载在翻页HTML一个div。我注意到,在Android的文档图片类,但我不知道是否可以被转换和保存。难道这通过JS来完成?任何想法?

I'm trying to implement the css3 page flip effect on a android/phonegap app. To do this, I need to dynamically save the current webview to png or jpeg so that it can be loaded to a div in the page flip html. I noticed the Picture class in android's docs but I'm not sure if that can be converted and saved. Could this be done through JS? Any ideas?

感谢

推荐答案

试试下面的$ C $下拍摄的WebView并保存JPG,以SD卡。

Try following code for capturing webview and saved jpg to 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");
 
精彩推荐
图片推荐