本文介绍了以截图的的WebView Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有HTML源代码和一个web视图我加载此源:
I have html source and with a WebView i load this source with:
WebView webView = (WebView) new WebView(getActivity());
webView = (WebView) rootView.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
String sourceHtml = (String) this.getActivity().getIntent().getExtras().get(ROW_ID1);
webView.loadData(sourceHtml, "text/html", "UTF-8");
现在我想保存此的WebView在SD卡位图或其他,我跟一些导游,但从来没有工作,我该怎么办呢?
Now i want to save this WebView in BitMap or other in the SdCard, i follow some guides but never works, how i can do it?
推荐答案
尝试使用capturePicture功能:
Try to use the capturePicture function:
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( "mnt/sdcard/screenshot.jpg" );
if ( fos != null )
{
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
}
}
catch(Exception e) {}
这篇关于以截图的的WebView Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!