热门标签 | HotTags
当前位置:  开发笔记 > Android > 正文

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

这篇文章主要介绍了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 

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

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

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


推荐阅读
author-avatar
薇薇MM81_811
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有