我有 html 源代码,并且使用 WebView 加载此源代码:
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 保存在 BitMap 中或 SdCard 中的其他内容,我遵循了一些指南但没有成功,我该怎么做?
最佳答案
尝试使用capturePicture
函数:
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) {}
关于android - 从 Android 中的 WebView 截取屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20919431/