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; Listbmps = new ArrayList (); for (int i = 0; i
需要多次截图的话,需要用到 view.destroyDrawingCache();
Bitmap normalViewScreenshot = ScreenShotUtils.getNormalViewScreenshot(mFrameContent); if (normalViewScreenshot != null) { Bitmap b = Bitmap.createBitmap(normalViewScreenshot); mImageResult.setImageBitmap(b); mFrameContent.destroyDrawingCache(); }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!