网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Android屏幕及view的截图实例详解

Android屏幕及view的截图实例详解

站在用户的角度思考问题,与客户深入沟通,找到铁门关网站设计与铁门关网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、做网站、企业官网、英文网站、手机端网站、网站推广、域名注册、网页空间、企业邮箱。业务覆盖铁门关地区。

屏幕可见区域的截图

整个屏幕截图的话可以用View view = getWindow().getDecorView();

public static Bitmap getNormalViewScreenshot(View view) {
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    return view.getDrawingCache();
  }

scrollview的整体截屏

public static Bitmap getWholeScrollViewToBitmap(View view) {
    view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();
    return bitmap;
  }

webview的整体截图

public static Bitmap getWholeWebViewToBitmap(WebView webView) {
    Picture snapShot = webView.capturePicture();
    Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);
    snapShot.draw(canvas);
    return bmp;
  }

listview的整体截图

public static Bitmap getWholeListViewItemsToBitmap(ListView listview) {

    ListAdapter adapter = listview.getAdapter();
    int itemscount = adapter.getCount();
    int allitemsheight = 0;
    List bmps = new ArrayList();

    for (int i = 0; i < itemscount; i++) {

      View childView = adapter.getView(i, null, listview);
      childView.measure(MeasureSpec.makeMeasureSpec(listview.getWidth(), MeasureSpec.EXACTLY),
          MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

      childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());
      childView.setDrawingCacheEnabled(true);
      childView.buildDrawingCache();
      bmps.add(childView.getDrawingCache());
      allitemsheight += childView.getMeasuredHeight();
    }

    Bitmap bigbitmap = Bitmap.createBitmap(listview.getMeasuredWidth(), allitemsheight, Bitmap.Config.ARGB_8888);
    Canvas bigcanvas = new Canvas(bigbitmap);

    Paint paint = new Paint();
    int iHeight = 0;

    for (int i = 0; i < bmps.size(); i++) {
      Bitmap bmp = bmps.get(i);
      bigcanvas.drawBitmap(bmp, 0, iHeight, paint);
      iHeight += bmp.getHeight();

      bmp.recycle();
      bmp = null;
    }
    return bigbitmap;
  }

需要多次截图的话,需要用到 view.destroyDrawingCache();

Bitmap normalViewScreenshot = ScreenShotUtils.getNormalViewScreenshot(mFrameContent);
        if (normalViewScreenshot != null) {
          Bitmap b = Bitmap.createBitmap(normalViewScreenshot);
          mImageResult.setImageBitmap(b);
          mFrameContent.destroyDrawingCache();
        }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!


网站栏目:Android屏幕及view的截图实例详解
网站地址:http://bjjierui.cn/article/peeeig.html

其他资讯