Android屏幕及view的截图实例详解
Android屏幕及view的截图实例详解
屏幕可见区域的截图
整个屏幕截图的话可以用Viewview=getWindow().getDecorView();
publicstaticBitmapgetNormalViewScreenshot(Viewview){ view.setDrawingCacheEnabled(true); view.buildDrawingCache(); returnview.getDrawingCache(); }
scrollview的整体截屏
publicstaticBitmapgetWholeScrollViewToBitmap(Viewview){ view.measure(MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED)); view.layout(0,0,view.getMeasuredWidth(),view.getMeasuredHeight()); view.buildDrawingCache(); Bitmapbitmap=view.getDrawingCache(); returnbitmap; }
webview的整体截图
publicstaticBitmapgetWholeWebViewToBitmap(WebViewwebView){ PicturesnapShot=webView.capturePicture(); Bitmapbmp=Bitmap.createBitmap(snapShot.getWidth(),snapShot.getHeight(),Bitmap.Config.ARGB_8888); Canvascanvas=newCanvas(bmp); snapShot.draw(canvas); returnbmp; }
listview的整体截图
publicstaticBitmapgetWholeListViewItemsToBitmap(ListViewlistview){ ListAdapteradapter=listview.getAdapter(); intitemscount=adapter.getCount(); intallitemsheight=0; Listbmps=newArrayList (); for(inti=0;i 需要多次截图的话,需要用到view.destroyDrawingCache();
BitmapnormalViewScreenshot=ScreenShotUtils.getNormalViewScreenshot(mFrameContent); if(normalViewScreenshot!=null){ Bitmapb=Bitmap.createBitmap(normalViewScreenshot); mImageResult.setImageBitmap(b); mFrameContent.destroyDrawingCache(); }感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!