简体   繁体   中英

How to capture a complete view of an Activity Screen in Android

I am using a scroll View in my activity.I want to share the whole activity screen but not able to do that.Am able to share the visible part of the screen but not the full screen of the activity.Is it possible to take the screenshot of the full activity.I have tried like this but its sharing only the visible part of the activity .Plz help me out of this.Thank You

   ShareImageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

             //View v1 = getWindow().getDecorView();

              View v1 = findViewById(android.R.id.content); 

             v1.setDrawingCacheEnabled(true); 
             myBitmap = v1.getDrawingCache();
             saveBitmap(myBitmap);


        }

    });

Saving the Screenshot taken ::

  public void saveBitmap(Bitmap bitmap) {
     String filePath = Environment.getExternalStorageDirectory()
     + File.separator + "Pictures/screencapture.png";
     File imagePath = new File(filePath);
     FileOutputStream fos;
     try {
     fos = new FileOutputStream(imagePath);
     bitmap.compress(CompressFormat.PNG, 100, fos);
     fos.flush();
     fos.close();
     share(filePath);
     } catch (FileNotFoundException e) {
     Log.e("exception1", e.getMessage(), e);
     } catch (IOException e) {
     Log.e("exception2", e.getMessage(), e);
     }
     }
 try this:

     public static Bitmap loadBitmapFromView(View v, int width, int height) {
Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);                
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM