Android中其实是可以用代码来实现截屏功能的,今天也是在这里无意中发现的(http://www.jianshu.com/p/4d21341f94ee),以前还真的不知道,记录一下以防忘记。
View rootView = getWindow().getDecorView().getRootView(); rootView.setDrawingCacheEnabled(true); Bitmap screenShotAsBitmap = Bitmap.createBitmap(rootView.getDrawingCache()); rootView.setDrawingCacheEnabled(false); iv_ping.setImageBitmap(screenShotAsBitmap);
方法二:
上边的方法在截图中有文本时会显示空白,在这里还有另外一种方法,经测试可以用:
(来自:http://stackoverflow.com/questions/9791714/take-a-screenshot-of-a-whole-view)
ScrollView iv = (ScrollView) findViewById(R.id.scrollView);
Bitmap bitmap = Bitmap.createBitmap(
iv.getChildAt(0).getWidth(),
iv.getChildAt(0).getHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
iv.getChildAt(0).draw(c);
// Do whatever you want with your bitmap
saveBitmap(bitmap);