Project requirements: screenshots of statistical charts are shared, but there are five statistical charts. The upper layer is scrollview. You have found a solution on the Internet:
[Java]
- /**
- * Capture the scrollview Screen
- ***/
- Public static Bitmap getBitmapByView (ScrollView scrollView ){
- Int h = 0;
- Bitmap bitmap = null;
- // Obtain the actual height of the listView.
- For (int I = 0; I <scrollView. getChildCount (); I ++ ){
- H + = scrollView. getChildAt (I). getHeight ();
- ScrollView. getChildAt (I). setBackgroundResource (R. drawable. bg3 );
- }
- Log. d (TAG, actual height: + h );
- Log. d (TAG, height: + scrollView. getHeight ());
- // Create a bitmap of the corresponding size
- Bitmap = Bitmap. createBitmap (scrollView. getWidth (), h,
- Bitmap. Config. ARGB_8888 );
- Final Canvas canvas = new Canvas (bitmap );
- ScrollView. draw (canvas );
- // Test output
- FileOutputStream out = null;
- Try {
- Out = new FileOutputStream (/sdcard/screen_test.png );
- } Catch (FileNotFoundException e ){
- E. printStackTrace ();
- }
- Try {
- If (null! = Out ){
- Bitmap. compress (Bitmap. CompressFormat. PNG, 100, out );
- Out. flush ();
- Out. close ();
- }
- } Catch (IOException e ){
- // TODO: handle exception
- }
- Return bitmap;
- }