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(); }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
網站題目:Android屏幕及view的截圖實例詳解
網站URL:http://vcdvsql.cn/article6/peeeig.html
成都網站建設公司_創新互聯,為您提供品牌網站建設、自適應網站、外貿網站建設、、虛擬主機、商城網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯