androidwebView截图的4种方法-创新互联
android 在webView里面截图大概有四种方式,具体内容如下

1.获取到DecorView然后将DecorView转换成bitmap然后写入到文件里面.
View view = getWindow().getDecorView();
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
Log.d(TAG,"bitmap--"+bitmap);
try {
String fileName = Environment.getExternalStorageDirectory().getPath()+"/webview_jietu.jpg";
FileOutputStream fos = new FileOutputStream(fileName);
//压缩bitmap到输出流中
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos);
fos.close();
Toast.makeText(WebviewFromGetDecorView.this, "截屏成功", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}finally {
if(bitmap!=null) {
bitmap.recycle();
}
}
网站标题:androidwebView截图的4种方法-创新互联
本文网址:http://www.jxjierui.cn/article/djpgco.html


咨询
建站咨询
