国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android屏幕及view的截圖實(shí)例詳解

2019-10-23 18:27:47
字體:
供稿:網(wǎng)友

Android屏幕及view的截圖實(shí)例詳解

屏幕可見區(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)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永昌县| 呈贡县| 云霄县| 新巴尔虎左旗| 敦化市| 从化市| 临潭县| 昌宁县| 合山市| 双牌县| 阿坝县| 枣阳市| 古蔺县| 临漳县| 安丘市| 赣州市| 长兴县| 宜良县| 邛崃市| 新巴尔虎左旗| 平罗县| 大荔县| 务川| 榆树市| 罗山县| 无棣县| 凤台县| 广德县| 瓦房店市| 凌源市| 东安县| 云浮市| 潢川县| 买车| 云安县| 滨海县| 柳江县| 安远县| 虎林市| 阳春市| 万荣县|