【发布时间】:2014-06-01 16:55:49
【问题描述】:
我在 webview 中的 html5 画布上画了一些线条,并尝试使用以下代码截取 webview 的屏幕截图...
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();
}
但是当我打开该图像时,它看起来是空的。请帮忙。
【问题讨论】:
标签: android html canvas webview