浩晨众云网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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(); } }