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

首頁 > 系統 > Android > 正文

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

2019-12-12 02:48:10
字體:
來源:轉載
供稿:網友

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

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丰城市| 桃江县| 静安区| 赣榆县| 中西区| 永昌县| 汤阴县| 兴宁市| 台南县| 河南省| 荆州市| 瑞丽市| 美姑县| 石景山区| 嘉祥县| 都江堰市| 鱼台县| 阜康市| 读书| 安多县| 区。| 仪征市| 乌鲁木齐县| 丰都县| 江都市| 寿阳县| 阳新县| 南宫市| 麻栗坡县| 大兴区| 花莲市| 元谋县| 红安县| 牡丹江市| 横峰县| 长子县| 泌阳县| 天祝| 德庆县| 广安市| 汝阳县|