我正在尝试在 android/phonegap 应用程序上实现 css3 翻页效果。为此,我需要将当前的 webview 动态保存为 png 或 jpeg,以便它可以加载到页面翻转 html 中的一个 div。我注意到 android 文档中的 Picture 类,但我不确定它是否可以转换和保存。这可以通过JS完成吗?有什么想法吗?
谢谢
最佳答案
尝试使用以下代码捕获 webview 并将 jpg 保存到 sdcard。
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
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( "/sdcard/" + "page.jpg" );
if ( fos != null ) {
b.compress(Bitmap.CompressFormat.JPEG, 90, fos );
fos.close();
}
}
catch( Exception e ) {
System.out.println("-----error--"+e);
}
}
});
webview.loadUrl("http://stackoverflow.com/questions/15351298/capturing-android-webview-image-and-saving-to-png-jpeg");
关于android - 捕获android webview图像并保存为png/jpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15351298/