最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android屏幕及view的截圖實例詳解

 更新時間:2017年05月26日 17:08:53   作者:笨鳥-先飛  
這篇文章主要介紹了Android屏幕及view的截圖實例詳解的相關(guān)資料,需要的朋友可以參考下

Android屏幕及view的截圖實例詳解

屏幕可見區(qū)域的截圖

整個屏幕截圖的話可以用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<Bitmap> bmps = new ArrayList<Bitmap>();

    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();
        }

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

平阴县| 保德县| 嘉义县| 商南县| 镇江市| 玉龙| 铜川市| 喀喇沁旗| 贵南县| 漳浦县| 衡水市| 会昌县| 白城市| 长沙县| 大埔县| 堆龙德庆县| 昌平区| 沾益县| 泗水县| 东兰县| 宾川县| 玉山县| 潜山县| 旺苍县| 东丽区| 吉林省| 纳雍县| 陆川县| 保亭| 合川市| 邮箱| 九龙坡区| 沭阳县| 紫金县| 承德县| 航空| 华阴市| 罗江县| 兴城市| 仁化县| 安阳市|