Android webview screenshot white border

女生的网名这么多〃 提交于 2020-01-05 19:31:25

问题


i followed this link to screenshot my webview completely. It works fine. But I have an issue. The screenhot that I get from the webview contains white spaces on the top and bottom of the picture? How do I get rid of this? Kindly let me know.

This is the code that I've used for capturing from webview. IF YOU LOOK PROPERLY THERE IS WHITESPACE BOTH AT THE BOTTOM AND TOP PARTS OF THE IMAGE.

    public static String saveCapturedImageToSdCard() {


        Picture picture = WebViewActivity.sWebViewEx.capturePicture();
        Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
        picture.getHeight(), Bitmap.Config.ARGB_8888);
        File file = null;
        Canvas c = new Canvas( b );

        picture.draw( c );
//        FileOutputStream fos = null;
        try {
            file = new File(Environment.getExternalStorageDirectory()+"/"+"temp.png");
            if(file != null && !file.exists())
                file.createNewFile();
            // write the bytes in file
            FileOutputStream fos = new FileOutputStream(file);
            fos = new FileOutputStream(file);
                if ( fos != null )
                {
                    b.compress(Bitmap.CompressFormat.PNG, 100, fos);

                    fos.close();
                }
            }
       catch( Exception e )
       {

       }
        return file.getPath().toString();
}

This is the image that I get from the webview:

My XML is:

<WebView
        android:id="@+id/webview"
        android:layout_below="@id/linearlayout_topbuttons"
        android:layout_above="@id/gallery_webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:overScrollMode="never"
        android:fitsSystemWindows="true"
        android:background="@android:color/transparent"
        android:layout_centerInParent="true"
        />

来源:https://stackoverflow.com/questions/14833051/android-webview-screenshot-white-border

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!