title: How to take screenshot of visible area of horizontalscrollview in android?
body: <p>I am working on an android app and I want to take screenshot of a visible area of horizontalscrollview. I am using below code for that :-</p>
  
  <pre><code>public Bitmap screenShot(View view) {
  
          /*Rect rect = new Rect(0, 0, 
                  mDiviceWidth , view.getHeight());*/
  
          /*Rect rect = new Rect(view.getScrollX(), 0, 
                  view.getScrollX() + mDiviceWidth , view.getHeight());*/
  
          Rect scrollBounds = new Rect();
      //  view.getHitRect(scrollBounds);
      //  view.getDrawingRect(scrollBounds);
      //  view.getLocalVisibleRect(scrollBounds);
      //  view.getGlobalVisibleRect(scrollBounds);
          view.getWindowVisibleDisplayFrame(scrollBounds);
          Log.e("X Scrolled", ""+view.getScrollX());
          Log.e("left", ""+scrollBounds.left);
          Log.e("right", ""+scrollBounds.right);
          Log.e("top", ""+scrollBounds.top);
          Log.e("bottom", ""+scrollBounds.bottom);
          /*view.setDrawingCacheEnabled(true);
          Bitmap bitmap = view.getDrawingCache();*/
          Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
                  view.getHeight(), Config.ARGB_8888);
  
          /*float left,right,top,bottom;
  
          left = view.getLeft();
          right =   mDiviceWidth;
          top = 0;
          bottom = view.getHeight();*/
  
          Canvas canvas = new Canvas(bitmap);
      //  canvas.clipRect(left, top, 
      //          right , bottom);
          canvas.clipRect(scrollBounds);
          view.draw(canvas);
      //  view.setDrawingCacheEnabled(false);
          return bitmap;
  
      } 
  </code></pre>
  
  <p>Above code is taking the screenshot but returning wrong area. Some times it captures visible area but sometimes it captures the random area  which is not visible or partial visible. I have already used </p>
  
  <pre><code>//  view.getHitRect(scrollBounds);
  //  view.getDrawingRect(scrollBounds);
  //  view.getLocalVisibleRect(scrollBounds);
  //  view.getGlobalVisibleRect(scrollBounds);
  </code></pre>
  
  <p>methods but not getting the perfect result.</p>
  
  <p>So please help me to resolve this issue. </p>