在Android 4.4系统的网络视图转换的Web视图图像不工作 [英] converting web view as image in Android 4.4 Web-view not working

查看:221
本文介绍了在Android 4.4系统的网络视图转换的Web视图图像不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用web视图显示D3图表的应用程序。下面是我用图表的URL的一个例子: HTTP:/ /nvd3.org/live$c$c/index.html#$c$cmirrorNav

I have an app that uses webview to display D3 charts. Here is an example of an url that I use for charts: http://nvd3.org/livecode/index.html#codemirrorNav

我能够加载图表和采取图表的截图太..但在这里与Android 4.4的问题是,它是不可能捕捉到的WebView与透明背景。

I am able to load the charts and taken a screenshot of that chart too.. But here the problem with android 4.4 is that it is not possible to capture the webview along with transparent background.

这是我的WebView

This is my webview

          <WebView
            android:id="@+id/chartView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight=".10"
            android:background="@drawable/chart_bg" >
           </WebView>

我申请了下面的属性到Web视图加载图表

I applied the below properties to the web view for loading the charts

    layoutView.getSettings().setJavaScriptEnabled( true );
    layoutView.requestFocusFromTouch();
    layoutView.setBackgroundColor(Color.TRANSPARENT);
    layoutView.getSettings().setBuiltInZoomControls( true );
    layoutView.getSettings().setLoadWithOverviewMode(true);
    layoutView.getSettings().setUseWideViewPort(true);

下面我将我的WebView为图像

Here i am converting my webview as image

 private void saveWebView() {

    //Resize the webview to the height of the webpage
    int pageHeight = layoutView.getContentHeight();
    LayoutParams browserParams = layoutView.getLayoutParams();
    layoutView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, pageHeight));

    //Capture the webview as a bitmap
    layoutView.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(layoutView.getDrawingCache());
    layoutView.setDrawingCacheEnabled(false);

    //Create the filename to use
    String randomFilenamepart = String.valueOf(new SecureRandom().nextInt(1000000));
    filename = Environment.getExternalStorageDirectory().toString() + "/Screenshot_" + randomFilenamepart + ".jpg";

    File imageFile = new File(filename);
    //Stream the file out to external storage as a JPEG
    OutputStream fout = null;
    try {
        fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fout);
        fout.flush();
        fout.close();

        Log.d("debug", "Screenshot taken successfully");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        layoutView.setLayoutParams(browserParams);
    }
}

通过这个我尝试捕捉网页视图沿下方的Andr​​oid 4.3的背景没有任何问题。但在Android 4.4奇巧,我捕捉到的WebView形象,但它是不是给web视图的背景。只是它显示有一个黑色的屏幕(不与我的背景图片)网络数据

By this i am try to capture the web view along with the background below Android 4.3 there's no problem. but On Android 4.4 kitkat, i capture the webview image but it is not giving the background of the webview. Just it is showing the web data with a black screen (not with my background image)

我该怎么解决呢?

推荐答案

我解决我的问题,通过另一种方式.. insted的设置背景图像Web视图我申请的背景图像我D3图。并取消了背景颜色也为我的Web视图。

I solved my problem by an alternative way.. Insted of setting the background image to web view i apply the background image to my D3 chart. And removed the background color also for my web view..

下面是code:

     <WebView
        android:id="@+id/chartView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight=".10" >
       </WebView>

Web视图属性。

Web view properties

layoutView.getSettings().setJavaScriptEnabled( true );
layoutView.requestFocusFromTouch();
layoutView.getSettings().setBuiltInZoomControls( true );
layoutView.getSettings().setLoadWithOverviewMode(true);
layoutView.getSettings().setUseWideViewPort(true);

背景我通过HTML(图输入)应用

background i am applied through the HTML (chart input)

<style>  body { overflow-y:scroll;  background:url(css/date_input_bg.png) no-repeat; } </style>

现在它的工作对我来说..但我仍然很惊人,为什么背景和背景颜色既没有工作只为Android 4.4系统这是工作在下面!

Now it working for me.. But still i am amazing why the background and background color both are not working only for Android 4.4 which is working in below!

这篇关于在Android 4.4系统的网络视图转换的Web视图图像不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆