How to capture everything currently on screen including Dialogs

前端 未结 3 1335
天命终不由人
天命终不由人 2021-01-12 23:30

I have looked at probably every SO article concering capturing the screen (screenshot, screendump) programmatically on Android, and they usually all end up with the same ans

相关标签:
3条回答
  • 2021-01-13 00:11

    This is working inside an opened DialogFragment.

    View v1 = ((ViewGroup) (((MyActivity)getActivity()).findViewById(android.R.id.content)));
    v1.setDrawingCacheEnabled(true);
    Bitmap bitmapParent = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);
    
    // dialogView is the inflated view of the DialogFragment
    dialogView.setDrawingCacheEnabled(true);
    Bitmap bitmapDialog = Bitmap.createBitmap(dialogView.getDrawingCache());
    dialogView.setDrawingCacheEnabled(false);
    
    Canvas canvas = new Canvas(bitmapParent);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bitmapDialog, 0, 0, paint);   
    
    // Activity and dialog captured!!
    bitmapParent.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(new File(directory, name)));
    
    0 讨论(0)
  • 2021-01-13 00:15

    use this library .... it works great for me. https://github.com/jraska/Falcon

      // Saving screenshot to file
                Falcon.takeScreenshot(this, imageFile);
                // Take bitmap and do whatever you want
                Bitmap bitmap = Falcon.takeScreenshotBitmap(this);
    
    0 讨论(0)
  • 2021-01-13 00:19

    It is possible, you need to draw all view roots to the bitmap. Try out this library: https://github.com/jraska/Falcon it can capture Dailogs to your screenshot.

    0 讨论(0)
提交回复
热议问题