//获取Picture对象
Picture picture = wv_capture.capturePicture();
//得到图片的宽和高(没有reflect图片内容)
int width = picture.getWidth();
int height = picture.getHeight();
if (width > 0 && height > 0) {
//创建位图
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
//绘制(会调用native方法,完成图形绘制)
picture.draw(canvas);
}
//获取webview缩放率 float scale = wv_capture.getScale(); //得到缩放后webview内容的高度 int webViewHeight = (int) (wv_capture.getContentHeight()*scale); Bitmap bitmap = Bitmap.createBitmap(wv_capture.getWidth(),webViewHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); //绘制 wv_capture.draw(canvas);
webView.setDrawingCacheEnabled(true); ... Bitmap bitmap = webView.getDrawingCache();
View view = context.getWindow().getDecorView();
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
保存到文件
try {
String fileName = Environment.getExternalStorageDirectory().getPath()+"/webview_capture4.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();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有