ScrollView screenshot code for android Development

Source: Internet
Author: User

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]
  1. /**
  2. * Capture the scrollview Screen
  3. ***/
  4. Public static Bitmap getBitmapByView (ScrollView scrollView ){
  5. Int h = 0;
  6. Bitmap bitmap = null;
  7. // Obtain the actual height of the listView.
  8. For (int I = 0; I <scrollView. getChildCount (); I ++ ){
  9. H + = scrollView. getChildAt (I). getHeight ();
  10. ScrollView. getChildAt (I). setBackgroundResource (R. drawable. bg3 );
  11. }
  12. Log. d (TAG, actual height: + h );
  13. Log. d (TAG, height: + scrollView. getHeight ());
  14. // Create a bitmap of the corresponding size
  15. Bitmap = Bitmap. createBitmap (scrollView. getWidth (), h,
  16. Bitmap. Config. ARGB_8888 );
  17. Final Canvas canvas = new Canvas (bitmap );
  18. ScrollView. draw (canvas );
  19. // Test output
  20. FileOutputStream out = null;
  21. Try {
  22. Out = new FileOutputStream (/sdcard/screen_test.png );
  23. } Catch (FileNotFoundException e ){
  24. E. printStackTrace ();
  25. }
  26. Try {
  27. If (null! = Out ){
  28. Bitmap. compress (Bitmap. CompressFormat. PNG, 100, out );
  29. Out. flush ();
  30. Out. close ();
  31. }
  32. } Catch (IOException e ){
  33. // TODO: handle exception
  34. }
  35. Return bitmap;
  36. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.