如何采取的WebView的截屏的Android [英] How to take screenshot of webview in Android
本文介绍了如何采取的WebView的截屏的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得出的WebView内对HTML5画布一些线条和尝试使用以下code采取的WebView的截图...
I have drawn some lines on html5 canvas within webview and tried to take screenshot of the webview using below code...
WebView webView = (WebView) findViewById(R.id.webview);
webView.setDrawingCacheEnabled(true);
Bitmap screenshot = Bitmap.createBitmap(webView.getDrawingCache());
webView.setDrawingCacheEnabled(false);
File myFile = new File(Environment.getExternalStorageDirectory().getPath()+ "/myfolder");
if(!myFile.exists()) {
myFile.mkdir();
}
imagePath = myFile.getAbsolutePath() + "/myimage001.png";
FileOutputStream fos = null;
try {
fos = new FileOutputStream(imagePath);
if ( fos != null ) {
screenshot.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
}
} catch( Exception e ) {
e.printStackTrace();
}
但是,当我打开图像,然后它看起来是空的。请帮忙。
But when I open that image then it looks empty. Please help.
推荐答案
执行如下:
private void TakeScreenshot()
{
Picture picture = webview.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/yahoo.jpg" );
if ( fos != null )
{
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
}
}
catch( Exception e )
{
}
}
N.B:乘坐的WebView
完成加载,否则你会得到一个空白屏幕后,屏幕截图
N.B: Take the screenshot after the WebView
finishes loading otherwise you will get a blank screen.
这篇关于如何采取的WebView的截屏的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文