1 获取当前可见的View的图片,类似于手机截屏View dView = getWindow().getDecorView();//获取DecorViewdView.setDrawingCacheEnabled(true);//生成View的副本,是一个BitmapBitmap bmp = dView.getDrawingCache();//获取View的副本,就是这个View上面所显示的任何内容2 获取任意View的内容图片
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);Canvas c = new Canvas(b);//使用bitmap构建一个Canvas,绘制的所有内容都是绘制在此Bitmap上的Drawable bgDrawable = v.getBackground();bgDrawable.draw(c);//绘制背景view.draw(c);//绘制前景return bitmap;如果是ListView,ScrollView,Webview等高度不固定的View,还需要手动计算出来高度来创建Bitmap,其他步骤相同
for (int i = 0; i < listView.getChildCount(); i++) {    h += listView.getChildAt(i).getHeight();}// 创建对应大小的bitmapbitmap = Bitmap.createBitmap(listView.getWidth(), h,        Bitmap.Config.ARGB_8888);

示例代码
//组合viewprivate Bitmap combineView(View topView, WebView centerView, View bottomView) {    float topWidth = topView.getWidth();    float topHeight = topView.getHeight();    float centerWidth = centerView.getWidth();    float centerHeight = centerView.getContentHeight() * centerView.getScale();    float bottomWidth = bottomView.getWidth();    float bottomHeight = bottomView.getHeight();    float width = Math.max(topWidth, Math.max(centerWidth, bottomWidth));//取最大的宽度作为最终宽度    float height = topHeight + centerHeight + bottomHeight;//计算总高度    Bitmap topBitmap = Bitmap.createBitmap((int) width, (int) topHeight, Bitmap.Config            .ARGB_8888);//顶部图片    topView.draw(new Canvas(topBitmap));    Bitmap centerBitmap = Bitmap.createBitmap((int) width, (int) centerHeight, Bitmap.Config            .ARGB_8888);//中部图片    centerView.draw(new Canvas(centerBitmap));    Bitmap bottomBitmap = Bitmap.createBitmap((int) width, (int) bottomHeight, Bitmap.Config            .ARGB_8888);//底部图片    bottomView.draw(new Canvas(bottomBitmap));    Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);//底图    Canvas canvas = new Canvas(bitmap);//画布    Paint paint = new Paint();    canvas.drawBitmap(topBitmap, 0, 0, paint);//画顶部    canvas.drawBitmap(centerBitmap, 0, topHeight, paint);//画中间    canvas.drawBitmap(bottomBitmap, 0, topHeight + centerHeight, paint);//画底部    return bitmap;}


更多相关文章

  1. android选择一张本机图片
  2. Android获取SHA1指纹
  3. android 获取摄像头像素
  4. 系统相册分析(GallerPicker)
  5. android几种图像之间转换
  6. Android(安卓)程式开发:(七)处理变化 —— 7.3 检测屏幕的方向
  7. Android(安卓)OpenGL ES 开发教程(11):绘制三角形Triangle
  8. Android(安卓)图片处理 之 Bitmap
  9. Android改变图片背景颜色tint(着色)或 backgroundTint

随机推荐

  1. Docker三年回顾:梦想依在,人生正当年
  2. Docker技术发展路线中囊括了新技术
  3. 八个问题帮你快速了解Docker
  4. 针对Docker容器的监控指标
  5. 将要改变IT世界的的docker技术是什么?
  6. 应对 Docker 网络功能难题的挑战与思考
  7. 如何实现 Docker 与分布式数据库结合
  8. docker 使用入门
  9. mysql新增纪录中某设有默认值的字段为nul
  10. 用 Docker 无脑备份数据库