-2

I am developing a GPA Calculator application. For that purpose, I want to install some features related to capturing the screenshot of the final activity where the user will see the subjects and their marks and GPA etc. My root view is ScrollView Layout (all the contents i.e subjects their marks) and wants to capture it. I tried the following code but the code works fine only for the single view

 Bitmap bitmap = Bitmap.createBitmap(text1.getWidth() , text1.getHeight() , Bitmap.Config.ARGB_4444);
                bitmap.setDensity(text1.getResources().getDisplayMetrics().densityDpi);
                Canvas canvas = new Canvas(bitmap) ;
                text1.draw(canvas);
                imageView.setImageBitmap(bitmap);

But if I try the same code for the Parent View i.e Scroll View it gives Exception

Caused by: java.lang.IllegalArgumentException: width and height must be > 0

I want to Capture the whole Scroll View And save it to Internal Drive !! Thanks in Advance

  • 1
    Possible duplicate of [IllegalArgumentException: width and height must be > 0 while loading Bitmap from View](https://stackoverflow.com/questions/17605662/illegalargumentexception-width-and-height-must-be-0-while-loading-bitmap-from) – Zoe Dec 23 '17 at 13:26
  • Please refer this thread https://stackoverflow.com/questions/43817116/take-a-full-screenshot-of-scrollview-android – Sivakumar S Dec 23 '17 at 14:08
  • @SivakumarS thanks ! – Saad Zahoor Dec 24 '17 at 14:41

1 Answers1

0

Use the drawingcache instead

Hope this helps

text1.setDrawingCacheEnabled(true);
Bitmap bitmap=text1.getDrawingCache();
Niza Siwale
  • 2,390
  • 1
  • 18
  • 20