在Android 4.4网络视图中将网络视图转换为图像不起作用
我有一个应用程序,使用webview显示D3图表。下面是我用于图表的url示例: 我能够加载图表并拍摄该图表的屏幕截图。。但安卓4.4的问题在于,它不可能捕获带有透明背景的网络视图 这是我的网络视图在Android 4.4网络视图中将网络视图转换为图像不起作用,android,webview,screenshot,android-4.4-kitkat,Android,Webview,Screenshot,Android 4.4 Kitkat,我有一个应用程序,使用webview显示D3图表。下面是我用于图表的url示例: 我能够加载图表并拍摄该图表的屏幕截图。。但安卓4.4的问题在于,它不可能捕获带有透明背景的网络视图 这是我的网络视图 <WebView android:id="@+id/chartView" android:layout_width="fill_parent" android:layout_height="fill_p
<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>
在这里,我将我的网络视图转换为图像
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);
}
}
通过这一点,我试图捕捉网络视图以及Android 4.3下的背景,没有问题。但在Android 4.4 kitkat上,我捕获了webview图像,但它没有提供webview的背景。只是它用黑屏显示web数据(不是我的背景图像)
我该怎么解决呢?我用另一种方法解决了我的问题。。我没有将背景图像设置为web视图,而是将背景图像应用于我的D3图表。并删除了我的web视图的背景色 代码如下:
<WebView
android:id="@+id/chartView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".10" >
</WebView>
背景我通过HTML应用(图表输入)
body{overflow-y:scroll;background:url(css/date\u input\u bg.png)不重复;}
现在它对我起作用了。。但我仍然很惊讶为什么背景和背景色都不适用于Android 4.4,而Android 4.4正在下面的版本中工作 网页中是否设置了背景色?就像背景色一样?@Murtaza Hussain是的。。我在我的网页上添加了透明背景。layoutView.setBackgroundColor(Color.TRANSPARENT);将其设置为白色。到网页的背景色是。如果我们将其设置为白色,它将为我的网络视图屏幕截图提供白色背景,但我需要一个用于网络视图的图像背景
<WebView
android:id="@+id/chartView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".10" >
</WebView>
layoutView.getSettings().setJavaScriptEnabled( true );
layoutView.requestFocusFromTouch();
layoutView.getSettings().setBuiltInZoomControls( true );
layoutView.getSettings().setLoadWithOverviewMode(true);
layoutView.getSettings().setUseWideViewPort(true);
<style> body { overflow-y:scroll; background:url(css/date_input_bg.png) no-repeat; } </style>